PHP - Creating Bridge Table In Mysql
HI. Im new to database. I didnt know how to use bridge table. In my bridge table i have SubjectID and studentID, PK from student table and subject table. In my subject table have SubjectID, SubjectName and SubjectLecturer while in my student table have studentID,,studentName,IC,studentFac,studentPhone, studentEmail,pswd,studentAddress. I didnt know where is the wrong part because when i click my form which is enroll button, this enroll page blank Can someone check my coding ? Help ?
<!DOCTYPE HTML> <html> <head> <?php
error_reporting(0); session_start(); if (!isset($_SESSION['studentID'])) { $_SESSION['studentID'] = $_POST['studentID']; $_SESSION['pswd'] = $_POST['pswd']; } include("connect.php"); $sql = "SELECT * FROM student WHERE studentID='".$_SESSION['studentID']."' AND pswd='".$_SESSION['pswd']."'"; $result = mysql_query($sql); $row = mysql_num_rows($result); if ($row == 0) { echo "Login fail Try again <a href='http://bytes.com/'>here</a>"; ?> <meta http-equiv="refresh" content="0;userlogin.php" /> <?php } else { $row = mysql_fetch_assoc($result); } ?> <meta charset="UTF-8"> <title>E-Education portal</title> <link href="http://bytes.com/style.css" rel="stylesheet" type="text/css"> </head> <body> <div id="header"></ div> <?php if(isset($_POST["submit"])) { session_start(); include("connect.php"); $SubjectID = $_POST['SubjectID']; $SubjectName = $_POST['SubjectName']; $SubjectLecturer = $_POST['SubjectLecturer']; $Subject= "SELECT SubjectID FROM Subject WHERE SubjectID='$SubjectID'"; $queryssubject=mysql_query($subject) or die(mysql_error); $record=mysql_num_rows($querysubject); if($record==1) { header ('Location: studentSubject.php'); } else if($record<1) { if(substr($subjectID)) { $insertIntoSubject= "INSERT INTO Subject ('SubjectID', 'SubjectName', 'SubjectLecturer') VALUES ('$SubjectID','$SubjectName','$SubjectLecturer')"; $result1=mysql_query($insertIntoSubject) or die(mysql_error()); $insertIntobridge="INSERT INTO `bridge`(`SubjectID`, `studentID`) VALUES ('$SubjectID', '$studentID')"; $result2=mysql_query($insertIntobridge)or die(mysql_error()); $insertIntostudent="INSERT INTO student (`studentID`, `studentName`, `IC`, `studentFac`, `studentPhone`, `studentEmail`, `pswd`, `studentAddress') VALUES ('$studentID', '$studentName', '$IC', '$studentFac', '$studentPhone', '$studentEmail', 'abc123', '$studentAddress')"; $result3=mysql_query($insertIntostudent)or die(mysql_error()); if ($result1 && $result2 && $result3) { header ('Location: studentSubject.php'); } } else echo 'insert error'; } else { echo "<script type='text/javascript'> alert('Data Updated!') location.href='homestudent.php' </script>"; } mysql_close($conn); } ?> Similar TutorialsWindows 7, Apache 2.2.21 / PHP 5.3.5. What does the below error mean? I am new and fighting through this particular piece of code. Thank you in advance for your help. Warning: mysql() expects parameter 3 to be resource, string given in C:\website\do_createtable.php on line 3 <? $db_name="booster"; $connection=mysql("localhost", "USERNAME", "PASSWORD") or die (mysql_error()); $db=mysql_select_db($db_name, $connection) or die (mysql_error()); $sql="CREATE TABLE $_POST[table_name] ("; for ($i=0; $i < count($_POST[field_name]); $i++) { $sql .= $_POST[field_name][$i]." ".$_POST[field_type][$i]; if ($_POST[field_length][$i] != "") { $sql .= " (".$_POST[field_length][$i]."),"; } else { $sql .= ","; } } $sql=substr($sql,0,-1); $sql .= ")"; $result=mysql_query($sql,$connection) or die (mysql_error()); if ($result) { $msg="<P>".$_POST[table_name]." has been created!</P>"; } ?> <HTML> <HEAD> <TITLE>Create a Database Table: Step 3</TITLE> </HEAD> <BODY> <h1>Adding table to <? echo "$db_name"; ?>....</h1> <? echo "$msg"; ?> </BODY> </HTML> Need a little help with this code. I'm running Apache 2.21 / PHP 5.3.5 on Windows. This is a V6 application. I am running Windows 7. I am new, and trying to learn. What am I doing wrong in line 8 with the 'if' statement? The idea is to create a table in mySQL using a form interface. Thank you in advance. Parse error: syntax error, unexpected '{' in C:\website\do_createtable.php on line 8 <? $db_name="booster"; $connection=mysql("localhost", "user", "password") or die (mysql_error()); $db=mysql_select_db($db_name, $connection) or die (mysql_error()); $sql="CREATE TABLE $_POST[table_name] ("; for ($i=0; $i < count($_POST[field_name]); $i++) { $sql .= $_POST[field_name][$i]." ".$_POST[field_type][$i]; if ($_POST[field_length][$i] != "" { $sql .= " (".$_POST[field_length][$i]."),"; } else { $sql .= ","; } } $sql=substr($sql,0,-1); $sql .= ")"; This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=357109.0 Alright, this has been puzzling me for a while now and I think it's time I seek help before my brain turns to mush. I've been modifying a PHP text based game called Legend of the Green Dragon to add more functionality, etc. One of the things I want to add is the ability to add levels higher then 15. The original array looks like this: $exparray = array(1=>100,2=>400,3=>1002,4=>1912,5=>3140,6=>4707, 7=>6641,8=>8985, 9=>11795,10=>15143,11=>19121,12=>23840, 13=>29437,14=>36071,15=>43930, ); Now, I could just hardcode each level, but noo, I want to be able to do it from a module type thing from the admin panel (which I've already gotten that working gratefully) so I've tried writing a few different scripts to take the information from the MySQL database and turn it into an array like above but I've gotten completely lost. This is what I currently have: $expsql = "SELECT * FROM " . db_prefix("myolevels"); $numrows = mysql_num_rows($expsql); for ($i = 1; $i <= $numrows; $i++) { $expresult = mysql_query($expsql); while ($rows = mysql_fetch_assoc($expresult)) { $exparray = array($i=>$rows['myoexpreq']); } } Although when I call the array, it always returns null for the myoexpreq causing your master to look for you all the time (forcing level up when it shouldn't be). Is there any way to create an array like the first with SQL? Thought this might help as well: PHP Warning: "Variable passed to each() is not an array or object" in /home/ileetcom/public_html/logd/lib/experience.php at 35. Call Stack: 2: each(NULL) called from /home/ileetcom/public_html/logd/lib/experience.php on line 35 3: exp_for_next_level(16, "0") called from /home/ileetcom/public_html/logd/village.php on line 131 I have the code below , and when I run it on my website , it returns a XML Parsing Error: not well-formed error , which says it has a problem reading the & i think
please see http://www.jamesflow...om/php/xml2.php
I think it has something to wiht the str_replace as when I change the $row['customerName'] . "</Name>\n"; to $row['customerNumber'] . "</Name>\n"; as a test it works fine , I understand XML cant handle special characters , how would prevent this happening?
code as below
$query = "SELECT * FROM customers"; $resultID = mysql_query($query, $linkID) or die("Data not found."); $xml_output = "<?xml version=\"1.0\"?>\n"; $xml_output .= "<entries>\n"; for($x = 0 ; $x < mysql_num_rows($resultID) ; $x++){ $row = mysql_fetch_assoc($resultID); $xml_output .= "\t<entry>\n"; $xml_output .= "\t\t<Name>" . $row['customerName'] . "</Name>\n"; // Escaping illegal characters $row['text'] = str_replace("&", "&", $row['text']); $row['text'] = str_replace("<", "<", $row['text']); $row['text'] = str_replace(">", ">", $row['text']); $row['text'] = str_replace("\"", """, $row['text']); $xml_output.= "\t\t<Number>" . $row['customerNumber'] . "</Number>\n"; $xml_output.= "\t</entry>\n"; } $xml_output .= "</entries>"; echo $xml_output; regards James Hi there,
I have a table in a MySQL database where I keep a list of user privileges. I am trying to create variables where the name of variable matches the privileges in the table.
This is also known as variable variables (I think).
EDIT (17/07/2014 04:02 PM): This might be a better way to describe what I'd like, so if the value from the table is admin_panel I'd like to dynamically create a variable with that name.
I have created a code so far, but all I seem to be getting is a list of Notice errors telling me that the variable is undefined. (I have supplied a list of errors a bit further down the post).
Here is the code:
<?php $host = "localhost"; $account = "***"; $password = "****"; $dbname = "****"; $connect = mysql_connect($host,$account,$password) or die("Unable To Connect"); $db = mysql_select_db($dbname,$connect) or die("Unable To Select DB"); $perm_query = "SELECT * FROM `privileges`"; $permission_query = mysql_query($perm_query); while($row = mysql_fetch_array($permission_query)) { $rows[] = $row; } foreach($rows as $row) { ${$row['privilege']}; } ?>The list of errors: Notice: Undefined variable: admin_panel in C:\xampp\htdocs\DynamicVariables.php on line 20 Notice: Undefined variable: create_user in C:\xampp\htdocs\DynamicVariables.php on line 20 Notice: Undefined variable: edit_user in C:\xampp\htdocs\DynamicVariables.php on line 20 Notice: Undefined variable: delete_user in C:\xampp\htdocs\DynamicVariables.php on line 20 Notice: Undefined variable: create_group in C:\xampp\htdocs\DynamicVariables.php on line 20 Notice: Undefined variable: edit_group in C:\xampp\htdocs\DynamicVariables.php on line 20 Notice: Undefined variable: delete_group in C:\xampp\htdocs\DynamicVariables.php on line 20 Notice: Undefined variable: view_log in C:\xampp\htdocs\DynamicVariables.php on line 20 Notice: Undefined variable: log_settings in C:\xampp\htdocs\DynamicVariables.php on line 20 Notice: Undefined variable: password_change in C:\xampp\htdocs\DynamicVariables.php on line 20 Thanks Edited by chrisrulez001, 17 July 2014 - 10:05 AM. It's about making a form for a web page. Which is better? Using table or divs? Which do you use? <form action='a.php' method='post'> <table> ............. </table> </form> <form action='a.php' method='post'> <div> ............. </div> </form> Hi there, trying to create a function more out of lazyness an timesaving than anything im sure it has to do with something combining the use of INSERT and x++ in an array, but im failing at figuring out the right way of doing it to achieve the right combination of effects. in simple need to create a 600x600 grid of co-ordinates where x starts at 1, ending in 600 with y starting at 1 and ending in 600 so basically a cubed set of entrys, (360,000 rows) not even sure thats possible lol.. the table only needs to contain the colums of id, x , y , ownerid (where id is auto inc) any suggestions, as you can tell its a pain-staking long case of affairs to create with a manual VERY long sql statement, trying to figure out a better way of doing this. help please? Thanks Hi guys, i cannot figure out what is wrong with this and I hope you could help figure it out? This is the code I am using - Code: [Select] $create_cart_table = "CREATE TABLE `". $string ."` (cart_id int NOT NULL AUTO_INCREMENT, PRIMARY KEY(cart_id), item_name VARCHAR(1000) NOT NULL, item_id VARCHAR(30) NOT NULL, price VARCHAR(30) NOT NULL, date_time TIMESTAMP(100) NOT NULL CURRENT_TIMESTAMP, quantity VARCHAR(100) NOT NULL)"; $set_cart_table = mysql_query($create_cart_table); $string is defined above and there are no database connection warnings etc coming up and I am lost as to how the heck this isn't working? It was working for about an hour when I first made the script but now it is not. Please help? I have a string (Product1-Product2-Product3#2-4-1) where Product1-Product2-Product3 are products and 2-4-1 are quantities. I am struggling to make a table out of it where products and quantities are shown in rows. here is what i tried. Code: [Select] list($products, $quantities) = explode("#", $specs); //to separate Quantities from products <?php foreach(preg_split("/-/", $products) as $product_list) { ?> <tr> <td> <?php echo $product_list; ?></td><? } ?> <?php foreach(preg_split("/-/", $quantities) as $qtylist) { ?> <td></td> <td><?php echo $qtylist; ?></td> <?php } ?> </tr> <?php //} ?> </table> I know something is wrong with this and its giving me unexpected reasult Please help me create a table out of the above string. Many Thanks -Max What I want to do is create a table out of records from a table that shows an image and a radio button under the image (so I would imagine it would be in 2 rows). I want it to have 3 columns across. Here's what I have to get and output the results: $fabricsql = "SELECT * FROM Fabric f, Images i WHERE f.SKU = i.SKU"; //echo $fabricsql; $fabricResult = mysql_query($fabricsql); $i=0; while($fabricAssoc = mysql_fetch_assoc($fabricResult)){ //echo $fabricAssoc['SKU']. "+ ".$fabricAssoc['Name']; echo "<a href=\"\"><img src='../../".$fabricAssoc['ThumbPath']."' alt='".$fabricAssoc['Description']."' width='".$fabricAssoc['ThumbWidth']."' /></a><br /> <input type=\"radio\" name=\"fabricSelect\" value='".$fabricAssoc['SKU']."' id=\"RadioGroup1_".$i."\" /><br /><br />"; $i++; } Any help is much appreciated. I'm not even sure this is the best way to go about this so any suggestions are appreciated. I've started a to-do app, and everything works fine. Every user has his own unique to-do items that he can add. The only issue is that when I log-in with a user, ALL the items of all users are displayed when I'm redirect to my main page. I want to make it as so every user has his own page where only the to-do items he has created are visible, not every item from every user. I'm a total beginner with PHP so I'm sorry if this is a stupid question. This is my todomain.php code <?php require 'db_conn.php'; require 'config.php'; session_start(); // If the session variable is empty, this // means the user is yet to login // User will be sent to 'login.php' page // to allow the user to login if (!isset($_SESSION['id'])) { $_SESSION['msg'] = "You have to log in first"; header('location: login.php'); } // Logout button will destroy the session, and // will unset the session variables // User will be headed to 'login.php' // after loggin out if (isset($_GET['logout'])) { session_destroy(); unset($_SESSION['id']); header("location: login.php"); } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset= "UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <link rel="stylesheet" href="css/bootstrap-grid.min.css"> <link rel="stylesheet" href="css/bootstrap.min.css"> <link rel="stylesheet" href="style.css"> <a href="index.php?logout='1'" style="color: black;"> Click here to Logout </a> <?php if (isset($_SESSION['success'])) : ?> <div class="error success" > <h3> <?php echo $_SESSION['success']; unset($_SESSION['success']); echo $_SESSION["username"] ?> </h3> </div> <?php endif ?> <title>TODO App</title> <script src="https://kit.fontawesome.com/d72928d9b9.js" crossorigin="anonymous"></script> </head> <body> <div class="container m-5 p-2 rounded mx-auto bg-light shadow"> <!-- App title section --> <div class="row m-1 p-4"> <div class="col"> <div class="p-1 h1 text-primary text-center mx-auto display-inline-block"> <i class="fa fa-check bg-primary text-white rounded p-2"></i> <u>My Todo-s</u> </div> </div> </div> <!-- Create todo section --> <form action="app/add.php" method="POST" autocomplete="off"> <div class="row m-1 p-3"> <div class="col col-11 mx-auto"> <div class="row bg-white rounded shadow-sm p-2 add-todo-wrapper align-items-center justify-content-center"> <div class="col"> <input class="form-control form-control-lg border-0 add-todo-input bg-transparent rounded" type="text" name="title" placeholder="Add new .."> </div> <div class="col-auto m-0 px-2 d-flex align-items-center"> <label class="text-secondary my-2 p-0 px-1 view-opt-label due-date-label d-none">Due date not set</label> <i class="fa fa-calendar my-2 px-1 text-primary btn due-date-button" data-toggle="tooltip" data-placement="bottom" title="Set a Due date"></i> <i class="fa fa-calendar-times-o my-2 px-1 text-danger btn clear-due-date-button d-none" data-toggle="tooltip" data-placement="bottom" title="Clear Due date"></i> </div> <div class="col-auto px-0 mx-0 mr-2"> <button type="submit" class="btn btn-primary">Add</button> </div> </div> </div> </div> </form> <?php $todos=$conn->query("SELECT * FROM todos ORDER BY id ASC"); ?> <div class="row mx-1 px-5 pb-3 w-80"> <div class="col mx-auto"> <?php while($todo=$todos->fetch(PDO::FETCH_ASSOC)){ ?> <!-- Todo Item 1 --> <div class="row px-3 align-items-center todo-item rounded"> <?php if($todo['checked']){ ?> <input type="checkbox" class="check-box" data-todo-id="<?php echo $todo['id'];?>" checked /> <h2 class="checked"><?php echo $todo['title'] ?> </h2> <div class="col-auto m-1 p-0 todo-actions"> <div class="row d-flex align-items-center justify-content-end"> </div> </div> <?php } else{ ?> <input type="checkbox" class="check-box" data-todo-id="<?php echo $todo['id'];?>"/> <h2><?php echo $todo['title'] ?></h2> <?php } ?> <div class="col-auto m-1 p-0 d-flex align-items-center"> <h2 class="m-0 p-0"> <i class="fa fa-square-o text-primary btn m-0 p-0 d-none" data-toggle="tooltip" data-placement="bottom" title="Mark as complete"></i> </h2> </div> <div class="col-auto m-1 p-0 todo-actions"> <div class="row d-flex align-items-center justify-content-end"> <h5 class="m-0 p-0 px-2"> <i class="fa fa-pencil text-info btn m-0 p-0" data-toggle="tooltip" data-placement="bottom" title="Edit todo"></i> </h5> <h5 class="m-0 p-0 px-2"> <i class="remove-to-do fa fa-trash-o text-danger btn m-0 p-0" data-toggle="tooltip" data-placement="bottom" title="Delete todo" id="<?php echo $todo['id']; ?>"></i> </h5> </div> <div class="row todo-created-info"> <div class="col-auto d-flex align-items-center pr-2"> <i class="fa fa-info-circle my-2 px-2 text-black-50 btn" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="Created date"></i> <label class="date-label my-2 text-black-50"><?php echo $todo['date_time'] ?></label> </div> </div> </div> </div> <?php } ?> </div> <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script> <script src="js/bootstrap.bundle.min.js"></script> <script src="js/myjs.js" ></script> <script src="js/jquery-3.3.1.min.js"></script> <script> $(document).ready(function(){ $(".remove-to-do").click(function(e){ const id = $(this).attr('id'); $.post('app/remove.php', { id: id }, (data) => { if(data){ $(this).parent().parent().parent().parent().hide(300); } } ); }); $(".check-box").click(function(e){ const id = $(this).attr('data-todo-id'); $.post('app/checking.php', { id: id }, (data) => { if(data!='error'){ const h2= $(this).next(); if(data === '1'){ h2.removeClass('checked'); }else{ h2.addclass('checked'); } } } ); }); }); </script> </body> </html>
I am trying to simplify my coding work for my website and wanting to make it operate more professionally (as part of my training to better my programming skills, which I know will take a lot of time to do). One of the things I`d like to improve on it is to create tables and fields in my mysql database, but not have to go into phpmyadmin to do it. I know open source programs like Drupal can do this easily so that when you add modules, the user does not have to access the database to set it up. But looking at the codes, I`m unable to figure out how it works. How will I be able to program my code to do something like, I`ll have a form where I enter in what I want the new table to be called, what fields to add in and their specifications, where I could do this by just going into my website as the admin? Can someone five me the correct code or format to use that will allow my TINYINT columns to carry TWO decimal places when creating my table? I have a script for creating the table and columns, but only recently learned that I need to ADD the TWO decimal place FUNCTION in order to get whole dollar values to display WITH the trailing zeros (ie.:2.00). I don't expect to need any values greater than xxx.xx in my columns, I'm just not clear on how to get the desired script when running the initial CREAT script. Thanks I'm in the process of creating a webage that shows latest scores and an updated league table for soccer/football matches like the bbc sports website does. I have the database set up with a form to update and display latest score all work well apart from if i update a score like the following teamA 1 teamB 0 it updates table to give teamA 3 points based on the current score however if teamA score again teamA 2 teamB 0 it updates table again but gives teamA another 3 points which is not correct so i need a way to stop it happening. thought about it for a while and only thing i can come up with is some maths to compare the values of score for each team and add/remove points as dependent on current score. Anyone got something similar to this Hello,
I have this very frustrating problem I'm trying to make a dynamic table with only 5 columns per row. So every 5 items, I need a new row. I have tried many different examples with no success. What is the best way to approach this? Here is what I am working with, this doesn't show what I have tried, just what I am working with at the moment which of course, just outputs it one column per row. http://www.mesquitew.../inc-legend.php // Lets parse the data $entries = simplexml_load_file($data); if(count($entries)): //Registering NameSpace $entries->registerXPathNamespace('prefix', 'http://www.w3.org/2005/Atom'); $result = $entries->xpath("//prefix:entry"); foreach ($result as $entry): $event = $entry->children("cap", true)->event; // Set the alert colors for the legend include ('../inc-NWR-alert-colors.php'); // Lets creat some styles for the list $spanStyle = "background-color:{$alertColor};border:solid 1px #333;width:15px;height:10px;display:inline-block;'> </span><span style='font-size:12px;color:#555;"; $legend .= "<table>"; $legend .= "<tr>"; $legend .= "<td> <span style='$spanStyle'> $event</span></td>"; $legend .= "</tr>"; $legend .= "</table>"; endforeach; endif; echo $legend;-Thanks! I need php code that creates pdf file with table inside. I made a table that gets the rows from a mysql table and lists them with the information on each row. What i need is an edit button at the end of the row so i can click it to change the data. What i want it to do is pop up a new window (child) that i can easily change the data by a text box, drop down menu, etc. and click submit to update it on the table. What i also need is a second button that will completely remove the data from that row in the table. I am still learning php and html and have no knowledge of javascript so any help would be appreciated! I am trying to create something similar to a bar chart, using a html table based on the values stored in an array. However, I cannot seem to get the next column to begin after printing the number at the bottom. I can get it going horizontal, but I would like to create a vertical version. If anyone can provide me with help I would greatly appreciate it. Code: [Select] <?php $month = date("n"); //numeric representation of month (1-12) $year = date("Y"); //4 digit representation of year $day = date("d"); //numeric representation of the day of the month // constant variable to determine how many days alive according to the current date define('DAYS_ALIVE',(($year - 1902) * 365.24) + (($month - 1) * 30.5 )+ ($day - 1)); $divident = 100000; // variable for modulus $divider = 10000; // variable to shrink the divident for($i = 0; $i <= 4; $i++) // for loop to fill the array with days alive { $daysArray[$i]= floor((DAYS_ALIVE % $divident)/$divider); //calculates the single digit to store in array $divident= $divident/10; //after every iteration the divident is decreased $divider= $divider/10; //after every iteration the divider is decreased } echo "<table border='2' width='100%'>"; $arraySize = count($daysArray); //variable for the array size for($k=0;$k<=$arraySize-1;$k++) { echo "<tr>"; for($j=1;$j<=$daysArray[$k];$j++) { echo "<td> * </td>"; } echo "<td>$daysArray[$k]</td>"; } echo "</table>"; ?> What I want is something like this. create table mimi (mimiId int(11) not null, mimiBody varchar(255) ); <?php //connecting to database include_once ('conn.php'); $sql ="SELECT mimiId, mimiBody FROM mimi"; $result = mysqli_query($conn, $sql ); $mimi = mysqli_fetch_assoc($result); $mimiId ='<span>No: '.$mimi['mimiId'].'</span>'; $mimiBody ='<p class="leading text-justify">'.$mimi['mimiBody'].'</p>'; ?> //what is next? i want to download pdf or text document after clicking button or link how to do that |