Jump to content

Trying To Keep Track Of Who Enters Database


Recommended Posts

I've been at this for a couple of days now so I can really say i have no idea. Im making a temporary parking pass kiosk. Users will enter their information and get a pass that matches that. Everything works except for trying to count how many passes they have gotten. I have been trying to do it this one way, and the fact i cant get past an error code tells me im doing it wrong. So i was wondering if anyone had any ideas on how i could start this. Ill post my code below to show you.

//add user plate to table $stmt = $conn->prepare("INSERT INTO count(plate) values(?)");$stmt->bind_param("s", $plate);$stmt->execute();$stmt->close();$sql="SELECT * FROM count where plate =$plate";$result=mysqli_query($conn,$sql);$row=mysqli_fetch_row($result);$counter=$row['counter'];// if have no limit value set counter = 1if(empty($counter)){$counter=1;$stmt = $conn->prepare("INSERT INTO count(limit) values(?)");$stmt->bind_param("s", $counter);    $stmt->execute();    $stmt->close();} //If limit is over three redirect to error pageelseif($counter > 3) {header("Location: error.html");}else{// add one more to limit$addcounter=$counter+1;$stmt3 = $conn->prepare("Update limit	  SET count =? where plate = $plate");    $stmt3->bind_param("s", $addcounter);    $stmt3->execute();    $stmt3->close();}

What i am trying to have happen is when the primary key is entered 'plate' it will add to the table "count". Along with adding that plate number, i want the 'limit' attribute to go up by one. Once user hit a maximum of three passes they will be given an error message and asked to see the attendant. Right now it tells me that nothing is attached to the attribute $plate, which i know is untrue because that variable is called upon at a different part of my script and that part works. Any ideas? Where am i going wrong.

Link to post
Share on other sites
Right now it tells me that nothing is attached to the attribute $plate, which i know is untrue because that variable is called upon at a different part of my script and that part works.
Ah, so the computer is wrong? The problem isn't that your assumptions are incorrect, but that the computer is wrong. As far as I can tell the computer is correct, because I don't see where you're setting those variables. You just showed the code where you're trying to use them. Another thing to consider is that COUNT and LIMIT are both keywords in SQL, so you may want to consider using different names.
Link to post
Share on other sites

No, i know I'm wrong. I want to know how i can make it right. I can link the rest of the script, but i use the same variable for a different part and when i take this part of the code out everything works correctly. Ok, read that last part too. Ill try changing those and see if that changes anything. I hadn't even considered that. Thanks a bunch :) If that doesnt work ill put the whole script on here.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...