outwarsecrets
Feb 3 2005, 07:49 PM
here is the code from the entire page. Everything seems to work except for the update query. Any suggestions on how I would go about fixing this? CODE <?php include ('includes/header.php'); ?> <table cellspacing="1" cellpadding="1" border="0" width="100%" bgcolor="000000"> <tr> <td align="center">Car Dealer</td> </tr> <tr> <td bgcolor="444444"><?php $query = mysql_query("SELECT * FROM `cars` ORDER BY `price` desc LIMIT 0 , 30"); while ($rows = mysql_fetch_array($query)){
$carid = $rows['id']; $price = $rows['price']; $year = $rows['year']; $name = $rows['name']; $image = $rows['image']; $description = $rows['description']; echo"$year $name for \$$price <a href=?buycar=$carid>Buy</a><br>"; } //check to see if there has been a call to delete a row if($_GET['buycar']){ //check to make sure that id exists $check = mysql_num_rows(mysql_query("SELECT * FROM `cars` WHERE `id` = '$carid'")); if($check < '1'){ echo"Invalid ID"; }else{ mysql_query("UPDATE `users` SET car='$carid', money=(money - price) WHERE uname='{$uname}'"); echo"Car has been purchased."; } }?></td> </tr> </table> <?php include ('includes/footer.php'); ?> this is also what the page looks like 1992 Saturn S-Series for $600 Buy 1987 Toyota Tercel for $500 Buy 1991 Chrysler Town and Country for $400 Buy 1989 Honda Accord for $350 Buy 1993 Ford Ranger for $300 Buy 1995 Geo Metro for $200 Buy the words Buy are links like the 1995 Geo Metro for $200 has the link dealer.php?buycar=5 If anyone can help me out I would really appreciate it.
Reply
Raptrex
Feb 4 2005, 01:47 AM
check that it is connecting to the database like your username, password, database name, and local host and if you have the tables for what you need
Reply
outwarsecrets
Feb 4 2005, 01:52 AM
I have checked, the db connection works fine. The list of cars at the bottom was taken from the database. Alos the other table is coonected correctly too. the users table has the following fields: uname, car, and money. Those all match up fine with what i have there.
Reply
LuciferStar
Feb 4 2005, 02:55 AM
I'm not quite clearly about your problem,is that something wrong with this: mysql_query("UPDATE `users` SET car='$carid', money=(money - price) WHERE uname='{$uname}'"); then try: mysql_query("UPDATE `users` SET car='$carid', money=($money - $price) WHERE uname='$uname'"); OR: mysql_query("UPDATE `users` SET car=\"".$carid."\", money=($money - $price) WHERE uname=\"".$uname."\"");
Reply
outwarsecrets
Feb 4 2005, 05:04 AM
i don't think it is something wrong with mysql_query("UPDATE `users` SET car='$carid', money=(money - price) WHERE uname='{$uname}'"); because i use it on another page on the site and that works fine. I will give it a try, but i think it is something with the if/else statements somewhere. Because everything works except when u click the link. It says "The car has been purchased" but nothing in the database changes. If anyone knows another way I could write something like that I would try to get that to work.
Reply
LuciferStar
Feb 4 2005, 11:18 AM
QUOTE(outwarsecrets @ Feb 4 2005, 05:04 AM) i don't think it is something wrong with mysql_query("UPDATE `users` SET car='$carid', money=(money - price) WHERE uname='{$uname}'"); Are you sure? in php,every vary name should be followed by a "$" this: money=(money - price) may cause problem,or the value of the money equals 1,that's because of the operation of '()'
Reply
bjrn
Feb 4 2005, 12:09 PM
I'd go so far as to try: CODE sqlstring="UPDATE `users` SET car=\"".$carid."\", money=".($money - $price)." WHERE uname=\"".$uname."\""; or CODE sqlstring="UPDATE `users` SET car=".$carid.", money=".($money - $price)." WHERE uname=\"".$uname."\""; followed by CODE mysql_query(sqlstring);
Depending on if carid is a varchar or int. I assume that the money field is an int type. Anyway, you could always try to echo the sqlstring and commenting out the querying. That way you can see exactly what your code is trying to execute. And you might want to check that uname='{$uname}'" shouldn't be uname='$uname'".
Reply
FaLgoR
Feb 4 2005, 05:30 PM
[quote=outwarsecrets,Feb 3 2005, 04:49 PM] CODE echo"$year $name for \$$price <a href=?buycar=$carid>Buy</a><br>";
just a little problem, you forgot an " " (space)  CODE $check = mysql_num_rows(mysql_query("SELECT * FROM `cars` WHERE `id` = '$carid'"));
I belive this ` is not really needed CODE mysql_query("UPDATE `users` SET car='$carid', money=(money - price) WHERE uname='{$uname}'");
first, you must put an $ before "price". And what is this {}?? Erase it. It will be: CODE mysql_query("UPDATE users SET car='$carid', money=(money - $price) WHERE uname='$uname'");
Here is all the errors I've saw here. Btw, what is the problem with this? Had u received an error msg? Post here..
Reply
LuciferStar
Feb 5 2005, 02:30 AM
QUOTE(FaLgoR @ Feb 4 2005, 05:30 PM) Here is all the errors I've saw here. Btw, what is the problem with this? Had u received an error msg? Post here.. THAT'S THE POINT!
Reply
karlo
Feb 5 2005, 06:00 AM
Now, first ZIP or RAR your file. Then let us download your code.
Reply
Similar Topics
Keywords : code, problem
- Create Table - Mysql Code - Help
(1)
Php Source Code Unveiled In Browser?
is that possible? (7) I am quite new to PHP and this concern came to my mind after playing around a bit with it... When
PHP is not correctly configured on the web server the source code of a php file we try to access
through a browser will be shown instead of the result of the code itself. This will normally not
happen when PHP is working properly, but I was just wondering if it could still be possible to see
that code if a user wanted to or if something on the server failed. This would for example expose
sensitive information like mysql passwords and so on... Is anything like that possib....
Malicious Code Injection
(3) Hi everyone! This is my first post, so be kind! Basically, I'm trying to get a free
host together so am writing some posts. Here's a little summin' summin' about malicious
code injection with PHP applications. Basically, this security exploit is one of the oldest tricks
in the books and all comes down to the fact that PHP allows execution of both local and remote
scripts with the SAME function... dur. Anyway, this is how it works. Image you've just employed
a young go getter, straight outta uni, who has found becoming a Jack of all trades a ....
Php And Mysql Programming
anyone knows a code for mysql and php (2) hi everyone! I am making a program using php and mysql...I am a noob on this so i need your
help guys...I want to make a simple program that will some values and then store them on a database
and then retrieve them...uhmm let me give an example out put of what i need. This is the example
say..: Enter First Name: Enter Last Name:
Enter Age: Enter Address: ..those
are the data needed for input values...my question now is how can I make a database....
Php Code Needed Iii
(10) Hello, everyone. I need your help again! Who might create the PHP code, the picture is
above this text. Basically, I want when the user fill in all the information in this form, it
automatically was sent to my email. And, then, the dialog box appears or on the same window, it was
said that your request has been sent. Moreover, if the user did not fill the entire information,
the dialog box appears stating that you did not fill some field. Thanks, for help. You always do
that.....
Php Code?
Mathematical Applications (12) Hello, everyone. The help is needed again. How can I make calculator in PHP language? That will act
like that a user just type in the fields known values, then click the button, and it's going to
be solved automatically. In other words, have can I write a formula in PHP, how to plug it inside
that language. For example, the formula to find a peremeter of square is: P=4a. So, a user
just can write the known value which is peremeter itself and it will find the side of a square; and
vice versa. If you can write many things how to do such formulas, such as comp....
Php Code Needed
Working Together? (5) Hello, everyone. I need your help again. This forum is quite good for it. Well, I need create a
registration form for my web-site using PHP and SQL. The information it should contain: 1) User
Name 2) First Name 3) Last Name 4) Password 5) e-mail Address 6) Security Image: that images helps
to protect a random registration, for instance, 56+2=where user have to type an answer in order to
finish registration. That's all for today. Anymore things, I will post another post over here.
....
Php Code
Needed?! (15) Well, I am a novice in PHP programming, so there is a script which I wanna get: 1. You go the
web-site 2. On the main screen, there is a some kind of field windows, the one you get used to type
in, when you go to google, for instance. 3. He or she types her email address and it's going to
be saved in my SQL database. 4. That's it. Help me if you can.....
Use Rss In Php Code
(3) so, how can I make RSS reader on my website? thanks in advance....
Will This Code Work
php linking script ?p= (5) hi i'm not that great at php so i'm not to sure if this will work or not. but what i want to
do is be able to use ?p=staff or what ever page name, with out the php extion, and i would like to
no if this simple script i made would work. the code is: CODE <?php $p =
$_GET['p']; if ( !empty($p) &&
file_exists('./' . $p . '.php') && stristr( $p, '.'
) == False ) { // pages = directory where you store your pages $file = './'
. $p . '....
I Need Some Proof Reading For My Code Please! [resolved]
(7) Well... everything is fine except the Content Select section (refer to the in-code headings)...
thats where it says the error is... could anyone find out why it wont work when I click one of my
links? http://2kart.trap17.com/progress.php for an example of what happens...
//----------------- //portfolio paths //----------------- $portfolio = "/portfolio"; $lay
= "/images"; //------------------ //navigation //------------------ $link = · Home
html; $link = · Portfolio html; $link = · Programming html; $link = ....
Html Code Tester. Online Script
(15) Yes, yes. I have another script that I have written and I am distributing. I am not entirely sure if
this works. I have not tested it yet, but I will later and post back with a demo and fix it up.
Current script: CODE <?php //Save this as something like htmltest.php function
CheckForm() { $html_unsafe=$_POST['code']; //Gives us our user
input $html_safe=str_replace("<?php"," ",$html_unsafe);
//Starts security measures $html_safe=str_replace("?>","
",$html_sa....
Awesome Source Code Viewer Script
(7) Hello! I have just came up with a sweet script to show the source code of any website and it
only requires one file. This is the basis of the script and can be customized with CSS and other
things and can be instituted as a public resource. Well I will provide the code and a step-by-step
tutorial on each of its parts. This code has been tested by me. Enjoy! CODE <?php
//This little tag starts our php script and is easily the most important part of the script. //We
will start our base script here. //You can change some of the styles used here to your des....
Whats Wrong>?
please see this piece of code and see whats wrong: (9) CODE require('connection2.php'); $select=mysql_query("SELECT * from
`users` WHERE password='$_GET[password]'");
$co=mysql_num_rows($select); if ($co = 1) {
session_start(); $s=session_id();
$_SESSION['access']="yes";
$username=$_GET['username'];
header("location:../main/index2.php?a=$_GET[username]&s=$s"
;); //echo "<a href='.&....
How To Make A Random 7 Number Code?
(2) I am making a script in php, and for it I need to know how to make a random 7 digit code. I think it
has something to do with md5, but i am not sure. Thanks! EDIT- Can someone please change the
title to "How to make a random 7 digit code in php?" Thanks!....
Php Education Class (first Code)
(0) Hi I want to educate some PHP codes that i think they will be useful for all of you! My 1st
code is this: CODE <?php class calculator { /** * Variable for holding all
the numbers to add * * @var array */ private $numbers = array();
/** * Variable holding all the digits after the point * * @var array */
private $afterPoint = array(); /** * Maximum number of digits after
the point * that a number has * * @var int */ private $....
My Code Doesnt Resize Large Images, Please Help.
(2) Can someone please have a look at the following code, this uploads an image, and make it in 2 sizes,
one size is max. 600 x 800, uploads to images folder and second 120 x 120 and uploads to thumbs
folder. this script works fine, with normal size images, but if i try to upload large pics( for
example, an image with dimension 2432 x 3300, it shows blank page, and uploads the original image
without sizing to "image" folder, and doesnt make any small thumbnail... I hope u understand..
Please someone help me, i shall be so thankful. session_start(); header("Cache-contro....
Some Basic Php Code Snippets For All Levels Of Experience
(3) Most of the code snippets are usually used for community driven sites but they do give some general
idea on how php works. Don't forget if your starting out php for the first time that when
saving php files that you need to have the .php extension on your files or they will not work.
Display Browser info This piece of code displays a user's browser info on how they are seeing
the website CODE <?php echo $_SERVER["HTTP_USER_AGENT"]; ?>
Actual Display- QUOTE Firefox - Mozilla/5.0 (Windows; U; Windows NT 5.1; ....
Use Bb Code On Your Site!
Just like on forums! (7) To use this you must have PHP support on your server. Just use this code: CODE <?php
$content = "Hello, World!"; $html = array('[b]',
'[/b]', '[i]', '[/i]', '[u]',
'[/u]'); $replacements = array ('<b>',
'</b>', '<i>', '</i>', '<u>',
'</u>'); $content = str_replace($html, $replacements,
$content); ?&....
Display The Current Date/time
With a simple PHP code (3) Use this code to display the current date and time. CODE <?php $date =
date('l dS \of F Y h:i:s A'); echo "$date"; ?>
"l" would display the current day of the week such as Sunday. d displays the day of the month...
such as 1 and S adds the appropriate suffix(st). /of simply displays the word "of". F displays the
current month with no abbreviations while Y displays the four digit year(2007). "h" displays the
current hour with leading zeros if necessary(Ex. 06 for 6 o'clock). "i" displays the m....
More Dynamic ?id=browsing With Php (associative Array)
Just create array and watch php code do the rest (1) The thing that has been bugging me for a while was that switch statement that we use to create ID
browsing (some use If-Ifelse but results are the same for both). I wanted to figure out a way to use
more dynamic switch statement so that i only need to update my links array in order to create links
for template. With use of foreach, array_keys, and in_array functions finally i managed to do so.
Also i'm planing on changing foreach with array_walk but i'll do that later. Now for the
code.. First we create an associative array something like this CODE $gl....
Help Me With My Code Please!
I can't find the bug! (4) Howdy, I've created a PHP script but it semms not to work, here's my script: if
(isset($_POST )) { $melding = ""; if ($_POST == "" ) { $melding .= "Je
moet eerst hier een map selecteren "; } else { $map = $_POST ;?>
Afbeelding Naam Verwijder $handle=opendir($map);
while (false!==($file = readdir($handle))) { if ($file != "." &&
$file != "..") { ?> "; ?> " /> " /> ....
Protecting My Code
from people that crack software (5) Is there any one way that I can protect something that I have written? 2 weeks ago I was contracted
to write a script for a friend in California for $300. I have known him for a while, and I
know he will respect my work, but if I sell this to other people how can I make sure they do the
same? I would like to sell this script to others. I have thought of a couple possible ways to
protect my code but I don't really like any of them. My question to you is whether I should use
one of these ideas, or if there is a simpler way to protect my work. My first idea w....
You Want It, I Can Make It
Request some code (49) Ok, i have this idea. I can make just about anything with php, so i would like to propose an offer:
Since i have absolutely no idea what to make i figured i could just have you guys tell me what you
would like and i could make it for you. That way we both win, i get to make something without having
to figure out what to make, and you get the code that you want. Sounds pretty simple doesnt it?
OK! Well there are a few rules: 1) Do not post your ideas if you feel that you do not want them
to be used by anyone else. However lets say that you want a forum as an example....
Wap Source Code Viewer
Mobile/wap source code viewer page (4) This is a source code viewer that will workl on wap/mobile sites but you can easily convert it to
work on web im sure ;-) CODE <? header("Content-Type:
text/vnd.wap.wml"); echo '<?xml version="1.0"
encoding="utf-8"?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml"> <wml> <head><meta
http-equiv="Cache-Control" content="no-cache"
forua="true"/></head> <card title="s60.nerds.....
Dynamic Image / Signature Generator
a simple code to change text on an image (12) In search of dynamically changing quote, saying or all other types of text on an image I came across
a code that I have modified to fit my initial usage. This procedure requires two files and short
knowledge of PHP. If you are familiar with Trap17's sig rotation code you will understand this
procedure very fast. Code 1: dynamic_sig.php (you can rename this to index.php and you'll see
at the end why) Code 2: a simple text file named anything (I will call it name.txt ) Code 1
CODE <?php header("Content-type: image/png"); ....
Adapting Html Code Embed To Work On Phpnuke
Help With This Html Code Pls (7) QUOTE how can get this html code to work on my phpnuke site? what tags would i
have to enable in the $Allowable HTML part of my config.php file?? Edited topic title. Moved
to Programming. ....
Change Permission With Php Code
code to change files' and folders' permissions? (3) As everyone know, there two ways (that I can think of) to change files' and directories'
permissions. One is to change it in your cPanel's Disk Manager and the other is with an FTP
client that supports chmod. Well, I'm doing something for my site that requires files to have
full permissions (Execute, Write, and Read on all three groups). At first, I thought that if I made
the directory 777, then every file created in that directory will be 777 as well. I'm wrong. An
alternative to doing this is to change each file permission myself, but that would be....
Php Clock
source Code (7) Hi Every one i find this code its very easy simple php clock i think you can use it /blink.gif'
border='0' style='vertical-align:middle' alt='blink.gif' /> CODE <? // Binary Clock //
script copyright© 2002 Andreas Tscharnuter // questions? contact: psychodad@psychodad.at ||
[url=http://www.psychodad.at/clock/]http://www.psychodad.at/clock/[/url] //
free to use, copy and modify but leave comments untouched;) // just include this file where
your binary clock should appear // version 1.2 03 September 2003 // below you can ....
How do you test your php code
(75) We know that php is a server side scripting language. So we will need a server with the php parser
to parse/test our code. How are you doing that. Do you upload it to a server for testing or did you
instal php and the server (apache) on your computer (localhost)....
Looking for code, problem
|
|
Searching Video's for code, problem
|
advertisement
|
|