Jump to content

Search the Community

Showing results for tags 'php mysql'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

  1. Can someone maybe help me. If I click on a record for instance d_name I want to show another another page that will contain the details of that record, the details is stored in a database table. What I want to do is if I click of the name of the company (d_name) then a new page must open which shows the information about that company that I will create. Here is my code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"><head> <title>Search</title> <meta name="description" content=""> <meta name="keywords" content=""> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <link href="css/style.css" rel="stylesheet" type="text/css"> </head> <body> <div class="main"> <div class="page"> <div class="header"> <div class="header-img"> <h1>Who Didn't Pay</h1> <p> </p> </div> <div class="menu"> <ul> <li><a href="index.php">Home</a></li> <li><a href="registration.php">Register</a></li> <li><a href="complaint.php">Complaint</a></li> <li><a href="search.php">Search</a></li> <li><a href="#">Contact Us</a></li> <li><a href="login.php">Login</a></li> <li><a href="logout.php">Logout</a></li> </ul> </div> </div> <div class="content"> <div class="left-panel"> <div class="left-panel-in"> <h2 class="title">All Companies:</h2> <p> </p> <p> </p> <p> <form method="post" action="allcompanies.php?go" id="showallform"> <p> </p> <p> </p> <table width="600" border="1" cellpadding="1" cellspacing="1"> <tr> <th>Company Name</th> <th>Email</th> <th>Companies not Paid</th> <th>Amount not Paid</th> <tr> </form> </p> </body></html> <?php //connect to the database $db=mysql_connect ("localhost", "root", "mj2015") or die ('I cannot connect to the database because: ' . mysql_error()); //-select the database to use $mydb=mysql_select_db("whodidntpay"); //-query the database table $sql="SELECT d_name,email,companies_not_paid,amount_not_paid FROM debtor ORDER BY d_name"; //-run the query against the mysql query function $result=mysql_query($sql); //-count results $numrows=mysql_num_rows($result); echo "<p>" .$numrows . " results found "; while($debtor=mysql_fetch_array($result)) { echo "<tr>"; echo "<td>".$debtor['d_name']."</td>"; echo "<td>".$debtor['email']."</td>"; echo "<td>".$debtor['companies_not_paid']."</td>"; echo "<td>".$debtor['amount_not_paid']."</td>"; } mysql_close($db); ?> I now want to click on a company name and then a page must be shown with the details of the company. Thank you
  2. Can someone maybe help me. I am new to php mysql and I am trying to create a search form where a user type in a name and the record of that name is displayed. Here is the error I get: Undefined variable: cname in C:\wamp\www\whodidntpay\search.php on line 32. Here is my code: <html> <head>Search</title> </head> <p> Company Name: <input type=text name=cname size=50 maxlength=50> <p> <input type=submit> <body> <table width="600" border="1" cellpadding="1" cellspacing="1"> <tr> <th>Company Name</th> <th>Reg</th> <th>Email</th> <th>Per</th> <th>Num</th> <th>NotPaid</th> <th>Amount</th> <tr> <?php mysql_connect('localhost', 'root', ''); mysql_select_db('whodidntpay'); // if ($cname == "") //{$cname = '%';} $sql="SELECT * FROM debtor WHERE cname LIKE '$cname%'"; $records=mysql_query($sql); ?> while ($debtor=mysql_fetch_assoc($records)) { echo "<tr>"; echo "<td>".$debtor['d_name']."</td>"; echo "<td>".$debtor['registration_nr']."</td>"; echo "<td>".$debtor['email']."</td>"; echo "<td>".$debtor['contact_person']."</td>"; echo "<td>".$debtor['contact_number']."</td>"; echo "<td>".$debtor['companies_not_paid']."</td>"; echo "<td>".$debtor['amount_not_paid']."</td>"; } </html> Thank you
  3. Can somebody maybe tell me is there an easier way to create the look of the website the html part. For example here is my code <html> <head> <title> Registration Form </title> </head> <body> <form method='post' action='registration.php'> <table width='400' border='5' align='center'> <tr> <td align='center' colspan='5'><h1>Registration Form</h1></td> </tr> <tr> <td>Email:</td> <td><input type='text' name='email' /></td> </tr> <tr> <td>Password:</td> <td><input type='password' name='password' /></td> </tr> <tr> <td>Company Name:</td> <td><input type='text' name='company' /></td> </tr> <tr> <td>Registration Number:</td> <td><input type='text' name='reg_nr' /></td> </tr> <tr> <td>Telephone Number:</td> <td><input type='text' name='telephone' /></td> </tr> <tr> <td>Address:</td> </tr> <tr> <td>Street:</td> <td><input type='text' name='street' /></td> </tr> <tr> <td>Suburb:</td> <td><input type='text' name='suburb' /></td> </tr> <tr> <td>City:</td> <td><input type='text' name='city' /></td> </tr> <tr> <td>Province:</td> <td><input type='text' name='province' /></td> </tr> <tr> <td>Postal Code:</td> <td><input type='text' name='postalcode' /></td> </tr> <tr> <td>Contact Person:</td> <td><input type='text' name='contact_person' /></td> </tr> <tr> <td>Contact Person Telephone Number:</td> <td><input type='text' name='contact_person_tel' /></td> </tr> <tr> <td colspan='5' align='center'><input type='submit' name='submit' value='Sign Up' /></td> </tr> </table> </form> <center><b>Already Registered</b><br><a href= 'login.php'>Login Here</a></center> </body> </html> <?php mysql_connect("localhost","root",""); mysql_select_db("whodidntpay"); if(isset($_POST['submit'])) { $com_password = $_POST['password']; $com_email = $_POST['email']; $com_companyname = $_POST['company']; $com_registration = $_POST['reg_nr']; $com_telephone = $_POST['telephone']; $com_street = $_POST['street']; $com_suburb = $_POST['suburb']; $com_city = $_POST['city']; $com_province = $_POST['province']; $com_postalcode = $_POST['postalcode']; $com_contactperson = $_POST['contact_person']; $com_contactpersontel = $_POST['contact_person_tel']; if($com_email=='') { echo "<script>alert('Please Enter Email')</script>"; exit(); } if($com_password=='') { echo "<script>alert('Please Enter Password')</script>"; exit(); } if($com_companyname=='') { echo "<script>alert('Please Enter Company Name')</script>"; exit(); } if($com_registration=='') { echo "<script>alert('Please Enter Registration Number')</script>"; exit(); } if($com_telephone=='') { echo "<script>alert('Please Enter Telephone Number')</script>"; exit(); } if($com_street=='') { echo "<script>alert('Please Enter Street Name')</script>"; exit(); } if($com_suburb=='') { echo "<script>alert('Please Enter Suburb Name')</script>"; exit(); } if($com_city=='') { echo "<script>alert('Please Enter City')</script>"; exit(); } if($com_province=='') { echo "<script>alert('Please Enter Province')</script>"; exit(); } if($com_postalcode=='') { echo "<script>alert('Please Enter Postel Code')</script>"; exit(); } if($com_contactperson=='') { echo "<script>alert('Please Enter Contact Person Name')</script>"; exit(); } if($com_contactpersontel=='') { echo "<script>alert('Please Enter Contact Person Telphone Nr')</script>"; exit(); } $check_email = "select * from complainant where email='$com_email'"; $run = mysql_query($check_email); if(mysql_num_rows($run)>0) { echo"<script>alert('Email $com_email already exists, please use another email')</script>"; exit(); } $query = "insert into complainant(email,password,company_name,registration_nr,telephone_nr,street,suburb,city,province,postal_code,contact_person,contact_person_tel) values ('$com_email','$com_password','$com_companyname','$com_registration','$com_telephone','$com_street','$com_suburb','$com_city','$com_province','$com_postalcode','$com_contactperson','$com_contactpersontel')"; if (mysql_query($query)) { echo "<script>alert('Registration Successful')</script>"; echo "<script>window.open('welcome.php','_self')</script>"; } } ?> Is there any way to create the html part with software and then just add the php part. Because doing it like this it is difficult for me to create a webpage that looks good.
  4. Can somebody tell me why there is two complaint records added to the complaint table when I am entering information of somebody and how I can fix it. Here is the new code <?php session_start(); if(!$_SESSION['email']) { header("location:login.php"); } ?> <html> <head> <title> Complaint </title> </head> <body> <form method='post' action='complaint.php'> <table width='800' border='10' align='left'> <tr> <td align='center' colspan='5'><h1>Complaint Form</h1></td> </tr> <tr> <td>Comany's Name:</td> <td><input type='text' name='comp_name' /></td> </tr> <tr> <td>Registration Number:</td> <td><input type='text' name='reg_nr' /></td> </tr> <tr> <td>Email:</td> <td><input type='text' name='comp_email' /></td> </tr> <tr> <td>Contact Person:</td> <td><input type='text' name='comp_contact_person' /></td> </tr> <tr> <td>Contact Number:</td> <td><input type='text' name='comp_contactnr' /></td> </tr> <tr> <td>Details of complain:</td> <td><input type='text' name='complain_details' /></td> </tr> <tr> <td>Order Number:</td> <td><input type='text' name='order_nr' /></td> </tr> <tr> <td>Order Description:</td> <td><input type='text' name='order_desc' /></td> </tr> <tr> <td>Order Date:</td> <td><input type='date' name='order_date' /></td> </tr> <tr> <td>Delivery Date:</td> <td><input type='date' name='delivery_date' /></td> </tr> <tr> <td>Invoice Date:</td> <td><input type='date' name='invoice_date' /></td> </tr> <tr> <td>Delivery Number:</td> <td><input type='text' name='delivery_nr' /></td> </tr> <tr> <td>Order Amount:</td> <td><input type='number' step='0.01' name='order_amount' /></td> </tr> <tr> <td>Amount Already Paid:</td> <td><input type='number' step='0.01' name='amount_paid' /></td> </tr> <tr> <td>Amount Outstanding:</td> <td><input type='number' step='0.01' name='amount_outstanding' /></td> </tr> <tr> <td colspan='5' align='center'><input type='submit' name='add_debtor' value='Submit' /></td> </tr> </table> </form> </body> </html> <?php mysql_connect("localhost","root","mj2015"); mysql_select_db("whodidntpay"); $log = $_SESSION['email']; if(isset($_POST['add_debtor'])) { $comp_name = $_POST['comp_name']; $comp_regnr = $_POST['reg_nr']; $comp_email = $_POST['comp_email']; $comp_contact_person = $_POST['comp_contact_person']; $comp_contact_nr = $_POST['comp_contactnr']; $complain_det = $_POST['complain_details']; $ordernr = $_POST['order_nr']; $orderdesc = $_POST['order_desc']; $orderdate = $_POST['order_date']; $deliverydate = $_POST['delivery_date']; $invoicedate = $_POST['invoice_date']; $deliverynr = $_POST['delivery_nr']; $orderamount = $_POST['order_amount']; $paidamount = $_POST['amount_paid']; $outstandamount = $_POST['amount_outstanding']; if($comp_name=='') { echo "<script>alert('Please Enter Company Name')</script>"; exit(); } if($comp_regnr=='') { echo "<script>alert('Please Enter Company Registration Number')</script>"; exit(); } if($comp_email=='') { echo "<script>alert('Please Enter Company Email')</script>"; exit(); } if($comp_contact_person=='') { echo "<script>alert('Please Enter Contact Person')</script>"; exit(); } if($comp_contact_nr=='') { echo "<script>alert('Please Enter Contact Number')</script>"; exit(); } if($complain_det=='') { echo "<script>alert('Please Enter Complain Details')</script>"; exit(); } if($ordernr=='') { echo "<script>alert('Please Enter Order Number')</script>"; exit(); } if($orderdesc=='') { echo "<script>alert('Please Enter Order Description')</script>"; exit(); } if($orderdate=='') { echo "<script>alert('Please Enter Order Date')</script>"; exit(); } if($deliverydate=='') { echo "<script>alert('Please Enter Delivery Date')</script>"; exit(); } if($invoicedate=='') { echo "<script>alert('Please Enter Invoice Date')</script>"; exit(); } if($deliverynr=='') { echo "<script>alert('Please Enter Delivery Number')</script>"; exit(); } if($orderamount=='') { echo "<script>alert('Please Enter Order Amount')</script>"; exit(); } if($paidamount=='') { echo "<script>alert('Please Enter Amount Paid')</script>"; exit(); } if($outstandamount=='') { echo "<script>alert('Please Enter The Amount Outstanding')</script>"; exit(); } $num_debt = "select * from debtor where d_name= '$comp_name' AND registration_nr= '$comp_regnr'"; $run = mysql_query($num_debt); $num_comp = mysql_num_rows($run); if ($num_comp ==0) $query = "insert into debtor(d_name,registration_nr,email,contact_person,contact_number,companies_not_paid,amount_not_paid) values ('$comp_name','$comp_regnr','$comp_email','$comp_contact_person','$comp_contact_nr','1','$outstandamount')"; if ($num_comp ==1) $query = "update debtor set companies_not_paid = companies_not_paid + 1, amount_not_paid = amount_not_paid + '$outstandamount' where d_name='$comp_name'"; if (mysql_query($query)) { echo "<script>alert('Company Added Successful')</script>"; } $complain_id = "select complainant_id from complainant where email = '$log'"; $run2=mysql_query($complain_id); $row = mysql_fetch_assoc($run2); $query2 = "insert into complaint(complain,d_name,complainant_id) values ('$complain_det','$comp_name','{$row['complainant_id']}')"; mysql_query($query2); $the_auto_id_that_was_just_created = mysql_insert_id(); if (mysql_query($query2)) { echo "<script>alert('Complaint Added Successful')</script>"; } $query3 = "insert into complaint_details(order_nr,order_description,order_date,delivery_date,invoice_date,delivery_nr,complaint_nr,order_amount,amount_paid,amount_outstanding) values ('$ordernr','$orderdesc','$orderdate','$deliverydate','$invoicedate','$deliverynr','$the_auto_id_that_was_just_created','$orderamount','$paidamount','$outstandamount')"; if (mysql_query($query3)) { echo "<script>alert('Complaint Details Added Successful')</script>"; } } ?> The insert command of complaint is at query2 almost at the end of the code. Thank you
  5. Can somebody maybe help me. I have got a complaint and complaint_details table. Complaint_nr is my primary key in complaint and foreign key in complaint_details. How can i show the complaint_nr in my complaint_details table. I have created the tables and in both there are a field for complaint_nr. It is an auto increment in complaint and also the primary key. And in complaint_details it is an int field and the foreign key. Here is my code. At $query3 I try to insert data into complaint_details. <?php session_start(); if(!$_SESSION['email']) { header("location:login.php"); } ?> <html> <head> <title> Complaint </title> </head> <body> <form method='post' action='complaint.php'> <table width='800' border='10' align='left'> <tr> <td align='center' colspan='5'><h1>Complaint Form</h1></td> </tr> <tr> <td>Comany's Name:</td> <td><input type='text' name='comp_name' /></td> </tr> <tr> <td>Registration Number:</td> <td><input type='text' name='reg_nr' /></td> </tr> <tr> <td>Email:</td> <td><input type='text' name='comp_email' /></td> </tr> <tr> <td>Contact Person:</td> <td><input type='text' name='comp_contact_person' /></td> </tr> <tr> <td>Contact Number:</td> <td><input type='text' name='comp_contactnr' /></td> </tr> <tr> <td>Details of complain:</td> <td><input type='text' name='complain_details' /></td> </tr> <tr> <td>Order Number:</td> <td><input type='text' name='order_nr' /></td> </tr> <tr> <td>Order Description:</td> <td><input type='text' name='order_desc' /></td> </tr> <tr> <td>Order Date:</td> <td><input type='date' name='order_date' /></td> </tr> <tr> <td>Delivery Date:</td> <td><input type='date' name='delivery_date' /></td> </tr> <tr> <td>Invoice Date:</td> <td><input type='date' name='invoice_date' /></td> </tr> <tr> <td>Delivery Number:</td> <td><input type='text' name='delivery_nr' /></td> </tr> <tr> <td>Order Amount:</td> <td><input type='number' step='0.01' name='order_amount' /></td> </tr> <tr> <td>Amount Already Paid:</td> <td><input type='number' step='0.01' name='amount_paid' /></td> </tr> <tr> <td>Amount Outstanding:</td> <td><input type='number' step='0.01' name='amount_outstanding' /></td> </tr> <tr> <td colspan='5' align='center'><input type='submit' name='add_debtor' value='Submit' /></td> </tr> </table> </form> </body> </html> <?php mysql_connect("localhost","root","mj2015"); mysql_select_db("whodidntpay"); $log = $_SESSION['email']; if(isset($_POST['add_debtor'])) { $comp_name = $_POST['comp_name']; $comp_regnr = $_POST['reg_nr']; $comp_email = $_POST['comp_email']; $comp_contact_person = $_POST['comp_contact_person']; $comp_contact_nr = $_POST['comp_contactnr']; $complain_det = $_POST['complain_details']; $ordernr = $_POST['order_nr']; $orderdesc = $_POST['order_desc']; $orderdate = $_POST['order_date']; $deliverydate = $_POST['delivery_date']; $invoicedate = $_POST['invoice_date']; $deliverynr = $_POST['delivery_nr']; $orderamount = $_POST['order_amount']; $paidamount = $_POST['amount_paid']; $outstandamount = $_POST['amount_outstanding']; if($comp_name=='') { echo "<script>alert('Please Enter Company Name')</script>"; exit(); } if($comp_regnr=='') { echo "<script>alert('Please Enter Company Registration Number')</script>"; exit(); } if($comp_email=='') { echo "<script>alert('Please Enter Company Email')</script>"; exit(); } if($comp_contact_person=='') { echo "<script>alert('Please Enter Contact Person')</script>"; exit(); } if($comp_contact_nr=='') { echo "<script>alert('Please Enter Contact Number')</script>"; exit(); } if($complain_det=='') { echo "<script>alert('Please Enter Complain Details')</script>"; exit(); } if($ordernr=='') { echo "<script>alert('Please Enter Order Number')</script>"; exit(); } if($orderdesc=='') { echo "<script>alert('Please Enter Order Description')</script>"; exit(); } if($orderdate=='') { echo "<script>alert('Please Enter Order Date')</script>"; exit(); } if($deliverydate=='') { echo "<script>alert('Please Enter Delivery Date')</script>"; exit(); } if($invoicedate=='') { echo "<script>alert('Please Enter Invoice Date')</script>"; exit(); } if($deliverynr=='') { echo "<script>alert('Please Enter Delivery Number')</script>"; exit(); } if($orderamount=='') { echo "<script>alert('Please Enter Order Amount')</script>"; exit(); } if($paidamount=='') { echo "<script>alert('Please Enter Amount Paid')</script>"; exit(); } if($outstandamount=='') { echo "<script>alert('Please Enter The Amount Outstanding')</script>"; exit(); } $num_debt = "select * from debtor where d_name= '$comp_name' AND registration_nr= '$comp_regnr'"; $run = mysql_query($num_debt); $num_comp = mysql_num_rows($run); if ($num_comp ==0) $query = "insert into debtor(d_name,registration_nr,email,contact_person,contact_number,companies_not_paid,amount_not_paid) values ('$comp_name','$comp_regnr','$comp_email','$comp_contact_person','$comp_contact_nr','1','$outstandamount')"; if ($num_comp ==1) $query = "update debtor set companies_not_paid = companies_not_paid + 1, amount_not_paid = amount_not_paid + '$outstandamount' where d_name='$comp_name'"; if (mysql_query($query)) { echo "<script>alert('Company Added Successful')</script>"; } $complain_id = "select complainant_id from complainant where email = '$log'"; $run2=mysql_query($complain_id); $row = mysql_fetch_assoc($run2); $query2 = "insert into complaint(complain,d_name,complainant_id) values ('$complain_det','$comp_name','{$row['complainant_id']}')"; if (mysql_query($query2)) { echo "<script>alert('Complaint Added Successful')</script>"; } $query3 = "insert into complaint_details(order_nr,order_description,order_date,delivery_date,invoice_date,delivery_nr,order_amount,amount_paid,amount_outstanding) values ('$ordernr','$orderdesc','$orderdate','$deliverydate','$invoicedate','$deliverynr','$orderamount','$paidamount','$outstandamount')"; } ?> Any help will be appreciated
  6. Can somebody maybe tell me why my insert command does not work correct. An user register and log in. Then the user can send a complaint. In my one table I want to show which user send the complaint via the complainant id. Here is the part of code not working: $log = $_SESSION['email']; $complain_id = "select complainant_id from complainant where email = '$log'"; $run2=mysql_query($complain_id); echo $run2; $query2 = "insert into complaint(complain,d_name,complainant_id) values ('$complain_det','$comp_name','$run2')"; if (mysql_query($query2)) { echo "<script>alert('Complaint Added Successful')</script>"; } Here is the whole complaint.php part: <?php session_start(); if(!$_SESSION['email']) { header("location:login.php"); } ?> <html> <head> <title> Complaint </title> </head> <body> <form method='post' action='complaint.php'> <table width='800' border='10' align='left'> <tr> <td align='center' colspan='5'><h1>Complaint Form</h1></td> </tr> <tr> <td>Comany's Name:</td> <td><input type='text' name='comp_name' /></td> </tr> <tr> <td>Registration Number:</td> <td><input type='text' name='reg_nr' /></td> </tr> <tr> <td>Email:</td> <td><input type='text' name='comp_email' /></td> </tr> <tr> <td>Contact Person:</td> <td><input type='text' name='comp_contact_person' /></td> </tr> <tr> <td>Contact Number:</td> <td><input type='text' name='comp_contactnr' /></td> </tr> <tr> <td>Details of complain:</td> <td><input type='text' name='complain_details' /></td> </tr> <tr> <td>Order Number:</td> <td><input type='text' name='order_nr' /></td> </tr> <tr> <td>Order Description:</td> <td><input type='text' name='order_desc' /></td> </tr> <tr> <td>Order Date:</td> <td><input type='date' name='order_date' /></td> </tr> <tr> <td>Delivery Date:</td> <td><input type='date' name='delivery_date' /></td> </tr> <tr> <td>Invoice Date:</td> <td><input type='date' name='invoice_date' /></td> </tr> <tr> <td>Delivery Number:</td> <td><input type='text' name='delivery_nr' /></td> </tr> <tr> <td>Order Amount:</td> <td><input type='number' step='0.01' name='order_amount' /></td> </tr> <tr> <td>Amount Already Paid:</td> <td><input type='number' step='0.01' name='amount_paid' /></td> </tr> <tr> <td>Amount Outstanding:</td> <td><input type='number' step='0.01' name='amount_outstanding' /></td> </tr> <tr> <td colspan='5' align='center'><input type='submit' name='add_debtor' value='Submit' /></td> </tr> </table> </form> </body> </html> <?php mysql_connect("localhost","root","mj2015"); mysql_select_db("whodidntpay"); $log = $_SESSION['email']; if(isset($_POST['add_debtor'])) { $comp_name = $_POST['comp_name']; $comp_regnr = $_POST['reg_nr']; $comp_email = $_POST['comp_email']; $comp_contact_person = $_POST['comp_contact_person']; $comp_contact_nr = $_POST['comp_contactnr']; $complain_det = $_POST['complain_details']; $ordernr = $_POST['order_nr']; $orderdesc = $_POST['order_desc']; $orderdate = $_POST['order_date']; $deliverydate = $_POST['delivery_date']; $invoicedate = $_POST['invoice_date']; $deliverynr = $_POST['delivery_nr']; $orderamount = $_POST['order_amount']; $paidamount = $_POST['amount_paid']; $outstandamount = $_POST['amount_outstanding']; if($comp_name=='') { echo "<script>alert('Please Enter Company Name')</script>"; exit(); } if($comp_regnr=='') { echo "<script>alert('Please Enter Company Registration Number')</script>"; exit(); } if($comp_email=='') { echo "<script>alert('Please Enter Company Email')</script>"; exit(); } if($comp_contact_person=='') { echo "<script>alert('Please Enter Contact Person')</script>"; exit(); } if($comp_contact_nr=='') { echo "<script>alert('Please Enter Contact Number')</script>"; exit(); } if($complain_det=='') { echo "<script>alert('Please Enter Complain Details')</script>"; exit(); } if($orderdesc=='') { echo "<script>alert('Please Enter Order Description')</script>"; exit(); } if($orderdate=='') { echo "<script>alert('Please Enter Order Date')</script>"; exit(); } if($deliverydate=='') { echo "<script>alert('Please Enter Delivery Date')</script>"; exit(); } if($invoicedate=='') { echo "<script>alert('Please Enter Invoice Date')</script>"; exit(); } if($deliverynr=='') { echo "<script>alert('Please Enter Delivery Number')</script>"; exit(); } if($orderamount=='') { echo "<script>alert('Please Enter Order Amount')</script>"; exit(); } if($paidamount=='') { echo "<script>alert('Please Enter Amount Paid')</script>"; exit(); } if($outstandamount=='') { echo "<script>alert('Please Enter The Amount Outstanding')</script>"; exit(); } $num_debt = "select * from debtor where d_name= '$comp_name' AND registration_nr= '$comp_regnr'"; $run = mysql_query($num_debt); $num_comp = mysql_num_rows($run); if ($num_comp ==0) $query = "insert into debtor(d_name,registration_nr,email,contact_person,contact_number,companies_not_paid,amount_not_paid) values ('$comp_name','$comp_regnr','$comp_email','$comp_contact_person','$comp_contact_nr','1','$outstandamount')"; if ($num_comp ==1) $query = "update debtor set companies_not_paid = companies_not_paid + 1, amount_not_paid = amount_not_paid + '$outstandamount' where d_name='$comp_name'"; if (mysql_query($query)) { echo "<script>alert('Company Added Successful')</script>"; } $complain_id = "select complainant_id from complainant where email = '$log'"; $run2=mysql_query($complain_id); echo $run2; $query2 = "insert into complaint(complain,d_name,complainant_id) values ('$complain_det','$comp_name','$run2')"; if (mysql_query($query2)) { echo "<script>alert('Complaint Added Successful')</script>"; } } ?> There is also a complainant table which consist of a complainant_id, email and password.
  7. I have a problem with a part of a function I have built. This part basically gets selects from the database those rows which have field1 as equal to $r['fieldx'] and echo them. When I try mysql_error() nothing gets put but when I do die("Error"), it gives Error so there is a problem with mysql_fetch_array(). Please help me because I've been trying to find the error for ages but still can't. $get = "SELECT * FROM ".TBL." WHERE test = '1' && (test = '".$fieldx['ShortVersion']."' || test2 = '".$fieldx['ShortVersion']."' || test3 = '".$fieldx['ShortVersion']."' || test4 = '".$fieldx['ShortVersion']."')"; $getprocess = mysql_query($get) or die(mysql_error()); echo "<br>Awarding ..."; //Debug ready till here while($getup = mysql_fetch_array($getprocess)) { // This does not run };
  8. I am trying to create dynamic categories nav for a gallery page. The structure of the nav would be: <ul> <li><a href="#">Category1</a> <ul> <li><a href="#">SubCategory1</a></li> <li><a href="#">SubCategory2</a></li> <li><a href="#">SubCategory3</a></li> </ul> </li> <li><a href="#">Category2</a> <ul> <li><a href="#">SubCategory1</a></li> <li><a href="#">SubCategory2</a></li> <li><a href="#">SubCategory3</a></li> </ul> </li> </ul> The current tables I created in my database are: categories idCat Category subcategories idSub subCategory cat_sub idCat idSub And what I have so far in PHP and MySQL statements is: <?php $con = mysql_connect("localhost", "xray", "password") or die('Could not connect to server'); mysql_select_db("xray", $con) or die('Sorry, could not connect to the database'); $query = "SELECT categories.Category, categories.idCat, subcategories.subCategory, subcategories.idSub FROM categories JOIN cat_sub ON categories.idCat = cat_sub.idCat JOIN subcategories ON subcategories.idSub = cat_sub.idSub"; $result = mysql_query($query) or die('Error'); while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ } ?> I think I am probably using the wrong join, as its returning each Category several times. And I am not sure how to structure the while loop to achieve the above mentioned structure. Any advice would be much appreciated. Thanks, Aleks
  9. i think the error is in query3 im not sure if i've formatted this correctly. <?php session_start(); //printf('<pre>%s</pre>', print_r($_SESSION, true)); require('includes/config.inc.php'); require('includes/session.php'); //WORKING DB_Connect(); $query = "SELECT * FROM food_delivery_orders_items WHERE food_delivery_orders_items.type = 'product' AND food_delivery_orders_items.order_id=".$_SESSION['pdf_quote']['id'].""; $result = mysql_query( $query) or die(mysql_error()); while($row = mysql_fetch_assoc($result)) { $hash = $row['hash']; $foreignid = $row['foreign_id']; $qty = $row['cnt']; } $query2 = "SELECT * FROM food_delivery_products WHERE food_delivery_products.id = ".$foreignid.""; $result2 = mysql_query( $query2) or die(mysql_error()); while($row = mysql_fetch_assoc($result2)) { $name = $row['name']; $description = $row['description']; } //--------------------------------------------------------------------------------------------------------------- $query3 = "SELECT * FROM food_delivery_orders_items WHERE food_delivery_orders_items.type = 'extra' AND food_delivery_orders_items.order_id=".$_SESSION['pdf_quote']['id'].""; $result3 = mysql_query( $query3) ; while($row = mysql_fetch_array($result3)) { $foreignidextra = $row['foreign_id']; $qtyextra = $row['cnt']; } print $row; $query4 = "SELECT * FROM food_delivery_extras WHERE food_delivery_extras.id = ".$foreignidextra.""; $result4 = mysql_query( $query4) or die(mysql_error()); while($row = mysql_fetch_array($result4)) { $nameextra = $row['name']; } echo $nameextra; echo $qtyextra; DB_Disconnect(); //$products = implode(", ",$_SESSION['pdf_quote']['product_arr']);; //print $products ?>
  10. Hi, I know a little about MySql but hardly anything about PHP and I am tasked with creating a customer ordering database which will have four different tables which need to have various joins. The database part I can handle. What I am struggling with is an Order Entry screen where the user puts in the customer name and does a search - if the system finds the customer then they can select it and create an order, if the system does not find the customer it gives the option to create a new customer record. Has anyone had any experience creating such a system and are there any PHP Templates available to assist creating the main input and search screens? Thanks Kate
  11. I'm new and I'm stuck. My code is supposed to geocode an address and then return the lat long (lat1, long1)....Then it calculates the distance between the gecoded location and some lat longs I have in my db (lat2, long2)...and then echo everything back so I can see what's being returned. Everything seems to work except the distance for the very first row in the db isn't being echoed back. Can anyone please help?? Here's the part I'm struggling with....the echo at the bottom misses the distance for the very first row although the results are returned. ....... $output= json_decode($geocode); $lat1 = $output->results[0]->geometry->location->lat; $long1 = $output->results[0]->geometry->location->lng; $jsonaddress = $output->results[0]->formatted_address; echo $jsonaddress.'<br>Lat: '.$lat1.'<br>Long: '.$long1; $raw_results = mysql_query("SELECT * FROM Artists WHERE (`First` LIKE '".$query1."%') AND (`Last` LIKE '".$query2."%')") or die(mysql_error()); function calculate_distance($long1, $lat1, $long2, $lat2) { return (3958 * 3.1415926 * sqrt(($lat2 - $lat1) * ($lat2 - $lat1) + cos($lat2 / 57.29578) * cos($lat1 / 57.29578) * ($long2 - $long1) * ($long2 - $long1)) / 180);} while($results = mysql_fetch_array($raw_results)) { $long2 = $results['Long']; $lat2 = $results['Lat']; if ( $long1 && $lat1 ) { $distance = calculate_distance($long2, $lat2, $long1, $lat1); } $distance = round($distance,0); echo "$distance Miles<br>"; echo "<p>".$results['First']." ".$results['Last']."</p>"; }} else{ ......
  12. I am a complete Newb where this PHP malarkey is concerned, however I have picked up a few basics and probably many more bad habits. The problem I have is the INSERT script and the UPDATE scripts have ceased working on Friday, the last time I know the INSERT worked was Thursday as items are added pretty much daily without any problems. All I have done is added 2 fields in the database 'salesperson' and 'made_live' and amended the scripts accordingly, when I realized it had stopped working I re-uploaded the original files and it still wasn't working, however I don't know if this is just coincidence or I've broken something. I can't for the life of me see any errors in the script but what do I know, (actually I wish to re-phrase that, I can't see any errors that would cause this problem, I'm sure that there are plenty of errors in it ;-) I would very much appreciate it if one of you experts could take a peek for me before I yank out what grey hair I have remaining. Many thanks in advance. Ian. INSERT Script: <?php //Connect to the MySQL database include"../scripts/connect_to_mysql.php"; if (!get_magic_quotes_gpc()) { $meta_desc=addslashes($_POST['meta_desc']); $sku=$_POST['sku']; $business_name=addslashes($_POST['business_name']); $address=$_POST['address']; $package=addslashes($_POST['package']); $contact_name=addslashes($_POST['contact_name']); $description=addslashes($_POST['description']); $phone=$_POST['phone']; $e_mail=$_POST['e_mail']; $short_web=$_POST['short_web']; $weblink=$_POST['weblink']; $facebook=$_POST['facebook']; $first_ad=$_POST['first_ad']; $main_menu=$_POST['main_menu']; $category=$_POST['category']; $sub_category=$_POST['sub_category']; $niche_category=$_POST['niche_category']; $display_ad=$_POST['display_ad']; $salesperson=$_POST['salesperson']; $made_live=addslashes($_POST['made_live']); } //* The script below fails to enter anything into the db*// $sql=mysql_query( "INSERT INTO business_list (id, meta_desc, sku, business_name, address, package, contact_name, description, phone, e_mail, short_web, weblink, facebook, first_ad, main_menu, category, sub_category, niche_category, display_ad, salesperson, made_live) VALUES ('NULL', '$meta_desc', 'NULL', '$business_name', '$address', '$package', '$contact_name', '$description', '$phone', '$e_mail', '$short_web', '$weblink', '$facebook', '$first_ad', '$main_menu', '$category', '$sub_category', '$niche_category', '$display_ad', '$salesperson', '$made_live')"); //*$lastid now returns '0' (as the INSERT failed) when the script worked before it would return the id, then that id is used to update the sku in the db for the review section.*// $lastid=mysql_insert_id(); $sql=mysql_query ($sql) or die ('<p></p><p></p>Database successfully updated with all the information relating to:<strong> ' . $business_name . ' </strong>, <p>USE THIS ID FOR AD IMAGE:<strong> ' . $lastid . ' </strong><form action="set_sku.php" method="post" enctype="multipart/form-data" name="set_sku"> <p>Now you need to update the SKU in the Database</P> <label>INPUT ID HERE TO UPDATE SKU AND CONTINUE TO ADD THE IMAGES</label> <input name="sku" type="text" maxlength="7" /> <input type="submit" value="Update SKU" /> </form> </p>'); mysql_close() ?> UPDATE Script: <?php include"../scripts/connect_to_mysql.php"; if (!get_magic_quotes_gpc()) { $ud_id=$_POST['ud_id']; $ud_sku=$_POST['ud_sku']; $ud_business_name=addslashes($_POST['ud_business_name']); $ud_address=addslashes($_POST['ud_address']); $ud_package=addslashes($_POST['ud_package']); $ud_contact_name=addslashes($_POST['ud_contact_name']); $ud_description=addslashes($_POST['ud_description']); $ud_meta_desc=addslashes($_POST['ud_meta_desc']); $ud_phone=$_POST['ud_phone']; $ud_e_mail=$_POST['ud_e_mail']; $ud_short_web=$_POST['ud_short_web']; $ud_weblink=$_POST['ud_weblink']; $ud_facebook=$_POST['ud_facebook']; $ud_first_ad=$_POST['ud_first_ad']; $ud_category=$_POST['ud_category']; $ud_sub_category=$_POST['ud_sub_category']; $ud_niche_category=$_POST['ud_niche_category']; $ud_display_ad=$_POST['ud_display_ad']; $ud_salesperson=$_POST['ud_salesperson']; $ud_made_live=addslashes($_POST['ud_made_live']); } //*The above script works as the data is displayed in the UPDATE form, the below script fails to actually do the UPDATE*// $query="UPDATE business_list SET sku='$ud_sku', business_name='$ud_business_name', address='$ud_address', package='$ud_package', contact_name='$ud_contact_name', description='$ud_description', meta_desc='$ud_meta_desc', phone='$ud_phone', e_mail='$ud_e_mail', short_web='$ud_short_web', weblink='$ud_weblink', facebook='$ud_facebook', first_ad='$ud_first_ad', main_menu='$ud_main_menu', category='$ud_category', sub_category='$ud_sub_category', niche_category='$ud_niche_category', display_ad='$ud_display_ad', salesperson='$ud_salesperson', made_live='$ud_made_live' WHERE id='$ud_id'"; mysql_query($query); echo "Record Updated"; mysql_close(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>SLBD - Admin</title> <link rel="stylesheet" href="../stylesheets/style.css" type="text/css" media="screen" /> </head> <body> <?php include_once("../templates/template_header.php"); ?> <h1> <?php echo "Record Updated"; ?></h1> <div id="contact" class="request"> <a href="log_out.php">[Log Out]</a> | <a href="reports_asc.php"> [Reports]</a> <table width="100%" border="0" cellpadding="40"> <tr><strong> <form action="admin.php" method="get" name="id"> <td align="center"> <input type="submit" value="Add an Advert" /> </td> </form> <form action="imageadmin.php"> <td align="center"> <input type="submit" value="Add or Update an Image" /> </td> </form> <form action="admin_update.php" method="get" name="id"> <td align="center"> <label>Update Ad with ID?</label><br /><br /> <input name="id" type="text" size="5" maxlength="7"> <br /><br /> <input type="submit" value="Update Advert" /> </td> </form> </strong> </tr> </table> </div> <br /> <?php include_once("../templates/template_footer.php"); ?> </body> </html> The CONNECT Script works fine because: the site displays correctly and uses the same script The UPDATE command collects the data, just won't do the UPDATE
  13. Hey there, using this mysql string: "SELECT name FROM monsters ORDER BY RAND() LIMIT 1" I retrieve a random monster encounter from my database. I have a question though, how would one influence the apperance rate of particular rows from my table? In practices this means that some monsters would appear more, some less.
  14. Hi All, I want to select rows from dynamic created tables i.e we have tables like web_analytics_mm_yy(ex: web_analytics_06_13, web_analytics_05_13, web_analytics_04_13 and so on) web_analytics ->common name for all tables mm_yy -> month_year( Will be creating each month) HOW to construct SQL STATEMENT USING UNION ALL? is there any thing that can be done using mysql Query only? and i want to know what is the best method to fetch data from multiple tables which are created dynamic. Thx ppl
  15. I have a website with a custome built CMS and am trying to be able to upload multiple images at once into a photo gallery. The following code is from the image module index,php file. The modules run through an admin section of the website ... sort of like www.mysite.com/admin/default.php/default.php?module=Gallery ... anyway, I can upload images, but only one at a time .... I must be missing something to allow me to select more than one image at once. When the selection window opens, I can only select one file at a time. What am I missing or doing wrong? <?php /**************************************************************************** My Gallery Module *****************************************************************************/ $docroot = "../"; $modulesDir = $docroot."modules/"; $moduleDir = "Gallery/"; $moduleName = "Gallery"; $username = $_SESSION['usersession']; // Figure out the user type $utidresult = mysql_query("SELECT utid FROM users WHERE username='$username'"); $utid = mysql_result($utidresult,0,"utid"); $typeresult = mysql_query("SELECT * FROM usertype WHERE utid=$utid"); $userType = mysql_result($typeresult,0,"type"); //check for type, if "Super" display all. IF ($userType!="Super"){ $checkQuery = "select * from userrights WHERE userid='$userid' AND module='$moduleName'"; $checkResult = mysql_query($checkQuery, $connection) or die("Query failed : " . mysql_error()); $access = ( mysql_num_rows($checkResult) > 0 ? 1 : 0 ); } ELSE{ $access=1; } if((($_SESSION['loggedin'])==yes)&&($access=='1')) { $do = $_GET["do"]; $urlString=$_SERVER['QUERY_STRING']; $exUrl = explode("&", $urlString); $subUrl = $exUrl[0]; $tableName = "gallery"; //Variables for the gallery $itemsPerRow = 3; $picsPerPage = 9; $itemCount = 0; $totalCount = 0; $tdWidth = 125; $trHeight = 100; error_reporting(E_ERROR | E_PARSE); $uploaddir = $modulesDir.$moduleDir."galleryimages/"; // Directory to store the main images $uploadTHdir = $modulesDir.$moduleDir."gallerythumbs/"; // Directory to store the thumbnails $curpage = $_GET['curpage']; echo "<span class=\"adminHeader\">Image Gallery Administration</span><br /><br />"; IF ($do == "addImage") { echo "<span class=\"actionHead\">Add an Image</span><br /><br />"; $page=$_GET['page']; $descriptionPost = addslashes($_POST['description']); $albumPost = addslashes($_POST['album']); $image = $_FILES['theImage']['name']; if($page=="submit"){$error = chkGalleryElements($image,$albumPost,$descriptionPost);} IF (($page=="submit")&&($error=="5")){ $maxfilesize = 5000000; $query = "SELECT MAX(iid) FROM gallery"; $result=mysql_query($query, $connection) or die("Query failed : " . mysql_error()); $maxImageId = max(mysql_fetch_array($result)); IF ($maxImageId==null){ $maxImageId=0; } $imageName = $maxImageId + 1; $uploadfile = "$uploaddir$imageName.jpg"; $uploadTHfile = $uploadTHdir."th_".$imageName.".jpg"; $uploadsize = $_FILES['theImage']['size']; /*== get file extension (fn at bottom of script) ==*/ /*== checks to see if image file, if not do not allow upload ==*/ $pext = getFileExtension($image); $pext = strtolower($pext); if (($pext != "jpg") && ($pext != "jpeg")) { print "<h1>ERROR</h1> The file you uploaded had the following extension: $pext.<br>"; print "<p>Please upload an image with the extension .jpg or .jpeg ONLY.<br><br>"; echo "<br /><br /><a href=\"default.php?$subUrl\"><img src=\"".$modulesDir.$moduleDir."imgs/return.gif\" height=\"31\" width=\"32\" alt=\"Return\" border=\"none\"/></a><span class=\"moduleReturnText\">Return to Gallery Administration</span>"; } elseif ($maxfilesize <= $uploadsize){ echo "The image that you have uploaded is too big. The system will accomodate any images up to 5MB and resize them to ensure optimal browsing. If your file is larger than this, please resize the image."; echo "<br /><br /><a href=\"default.php?$subUrl\"><img src=\"".$modulesDir.$moduleDir."imgs/return.gif\" height=\"31\" width=\"32\" alt=\"Return\" border=\"none\"/></a><span class=\"moduleReturnText\">Return to Gallery Administration</span>"; } else { if (move_uploaded_file($_FILES['theImage']['tmp_name'], $uploadfile)) { // The file $filename = $uploadfile; $desiredwidth = 390; $desiredthumb_width = 150; // Get new dimensions list($width, $height) = getimagesize($filename); IF ($width > 390){ $new_width = $desiredwidth; $new_height = $desiredwidth/$width * $height; } ELSE{ $new_width = $width; $new_height = $height; } IF ($width > 150){ $new_thumb_width = $desiredthumb_width; $new_thumb_height = $desiredthumb_width/$width * $height; } ELSE{ $new_thumb_width = $width; $new_thumb_height = $height; } // Resample $image_p = imagecreatetruecolor($new_width, $new_height); $image = imagecreatefromjpeg($filename); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); $image_t = imagecreatetruecolor($new_thumb_width, $new_thumb_height); $imagethumb = imagecreatefromjpeg($filename); imagecopyresampled($image_t, $imagethumb, 0, 0, 0, 0, $new_thumb_width, $new_thumb_height, $width, $height); // Output imagejpeg($image_p, "$uploadfile", 100); imagejpeg($image_t, "$uploadTHfile", 100); $query = "INSERT INTO gallery VALUES ('','$imageName','$descriptionPost','$albumPost')"; mysql_query($query, $connection) or die("Query failed : " . mysql_error()); echo "Thank-you image has been added to the gallery.<br /><br />"; echo "<a href=\"default.php?$subUrl\"><img src=\"".$modulesDir.$moduleDir."imgs/return.gif\" height=\"31\" width=\"32\" alt=\"Return\" border=\"none\"/></a><span class=\"moduleReturnText\">Return to Gallery Administration</span>"; } else { echo "File upload is not valid. Check permissions or contact the system administrator."; echo "<br /><br />"; echo "<a href=\"default.php?$subUrl\"><img src=\"".$modulesDir.$moduleDir."imgs/return.gif\" height=\"31\" width=\"32\" alt=\"Return\" border=\"none\"/></a><span class=\"moduleReturnText\">Return to Gallery Administration</span>"; } } } ELSE{ //code to display the editor which replaces the textarea. echo "<script type=\"text/javascript\" src=\"" ."$docroot" ."editor/fckeditor.js\"></script>" ."<script type=\"text/javascript\">" ."window.onload = function()" ."{" ."var oFCKeditor = new FCKeditor( 'description','','250','Default','' ) ;" ."oFCKeditor.BasePath = '" ."$docroot" ."editor/' ;" ."oFCKeditor.ReplaceTextarea() ;" ."}" ."</script>"; //editor code end IF ($error==2){ echo "<font color=\"red\">Please check to ensure that all fields have been filled.</font><br /><br />"; $error==0; } echo "<table width=\"100%\">" ."<form enctype=\"multipart/form-data\" action=\"default.php?$urlString&page=submit\" method=\"POST\">" ."<tr><td width=\"120\">" //<!-- Name of input element determines name in $_FILES array --> ."<b>Choose Image: </b></td><td><input name=\"theImage[]}\" type=\"file\" multiple/></td></tr>" ."<tr><td width=\"80\"><strong>Add to Album:</strong></td><td>" ."<select name=\"album\" size=\"1\">" ."<option selected"; if (($albumPost!=null)||($albumPost!="")){ echo "value=\"$albumPost\">"; $albumNameQuery = "SELECT * from galleryalbum where aid=$albumPost"; $albumNameResult = mysql_query($albumNameQuery, $connection) or die("Query failed : " . mysql_error()); $albumName = mysql_result($albumNameResult,0,"aname"); echo stripslashes($albumName); } else{ echo ">"; } echo "</option>"; $query = "SELECT * FROM galleryalbum"; $result = mysql_query($query, $connection) or die("Query failed : " . mysql_error()); $numrows = mysql_num_rows($result); for ($i = 0; $i < $numrows; $i++) { $aname = mysql_result($result,$i,"aname"); $aid = mysql_result($result,$i,"aid"); echo "<option value=\"$aid\">"; echo $aname; echo "</option>"; } echo "</select>"; echo "</td></tr>" ."<tr><td colspan=\"2\" height=\"10\"></td></tr>" ."<tr><td colspan=\"2\"><b>Description:</b><br /></td></tr>" ."<tr><td colspan=\"2\" height=\"100\"><textarea name=\"description\" rows=\"8\" cols=\"75\">"; if (($descriptionPost!=null)||($descriptionPost!="")){ echo stripslashes($descriptionPost); } echo "</textarea></td></tr>" ."<tr><td colspan=\"2\" height=\"10\"></td></tr>" ."<tr><td colspan=\"2\" height=\"10\">" ."<input type=\"submit\" value=\"Submit\" />" ."</td></tr>" ."</form>" ."</table>"; echo "<br /><br /><a href=\"default.php?$subUrl\"><img src=\"".$modulesDir.$moduleDir."imgs/return.gif\" height=\"31\" width=\"32\" alt=\"Return\" border=\"none\"/></a><span class=\"moduleReturnText\">Return to Gallery Administration</span>"; } } ELSEIF ($do=="modImage"){ $page=$_GET['page']; $iid = $_GET['iid']; $albumPost=addslashes($_POST['album']); $imageName=addslashes(basename($_FILES['theImage']['name'])); $descriptionPost=addslashes($_POST['description']); $maxfilesize = 5000000; if ($page=="submit"){$error = chkModGalleryElements($albumPost,$descriptionPost);} echo "<span class=\"actionHead\">Modify an Image</span>" ."<br /><br />"; IF (($page=="submit")&&($error==5)){ $oldImageQuery = "SELECT * FROM gallery WHERE iid=$iid"; $oldImageResult = mysql_query($oldImageQuery, $connection) or die("Query failed : " . mysql_error()); $oldImageName = stripslashes(mysql_result($oldImageResult,0,"imageName")); IF ($imageName!=null){ $uploadfile = $uploaddir.$oldImageName; $uploadfile = $uploaddir.$oldImageName.".jpg"; $uploadTHfile = $uploadTHdir."th_".$oldImageName.".jpg"; $image = $_FILES['theImage']['name']; $uploadsize = $_FILES['theImage']['size']; $pext = getFileExtension($image); $pext = strtolower($pext); if (($pext != "jpg") && ($pext != "jpeg")) { print "<h1>ERROR</h1> The file you uploaded had the following extension: $pext.<br>"; print "<p>Please upload an image with the extension .jpg or .jpeg ONLY.<br><br>"; echo "<br /><br /><a href=\"default.php?$subUrl\"><img src=\"".$modulesDir.$moduleDir."imgs/return.gif\" height=\"31\" width=\"32\" alt=\"Return\" border=\"none\"/></a><span class=\"moduleReturnText\">Return to Gallery Administration</span>"; } elseif ($maxfilesize <= $uploadsize){ echo "The image that you have uploaded is too big. The system will accomodate any images up to 5MB and resize them to ensure optimal browsing. If your file is larger than this, please resize the image."; echo "<br /><br /><a href=\"default.php?$subUrl\"><img src=\"".$modulesDir.$moduleDir."imgs/return.gif\" height=\"31\" width=\"32\" alt=\"Return\" border=\"none\"/></a><span class=\"moduleReturnText\">Return to Gallery Administration</span>"; } else { if (move_uploaded_file($_FILES['theImage']['tmp_name'], $uploadfile)) { //remove old image $filePath = $uploaddir . $oldImageName; unlink($filePath); $thFilePath = $uploadTHdir . "th_".$oldImageName; unlink($thFilePath); // The file $filename = $uploadfile; $desiredwidth = 390; $desiredthumb_width = 150; // Get new dimensions list($width, $height) = getimagesize($filename); IF ($width > 390){ $new_width = $desiredwidth; $new_height = $desiredwidth/$width * $height; } ELSE{ $new_width = $width; $new_height = $height; } IF ($width > 150){ $new_thumb_width = $desiredthumb_width; $new_thumb_height = $desiredthumb_width/$width * $height; } ELSE{ $new_thumb_width = $width; $new_thumb_height = $height; } // Resample $image_p = imagecreatetruecolor($new_width, $new_height); $image = imagecreatefromjpeg($filename); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); $image_t = imagecreatetruecolor($new_thumb_width, $new_thumb_height); $imagethumb = imagecreatefromjpeg($filename); imagecopyresampled($image_t, $imagethumb, 0, 0, 0, 0, $new_thumb_width, $new_thumb_height, $width, $height); // Output imagejpeg($image_p, "$uploadfile", 100); imagejpeg($image_t, "$uploadTHfile", 100); $query = "UPDATE gallery SET description='$descriptionPost', aid='$albumPost' WHERE iid='$iid'"; $result = mysql_query($query, $connection) or die("Query failed : " . mysql_error()); echo "Thank you, the image has been modified. This image can be further edited at any time from the Gallery section of the administration." ."<br /><br />"; echo "<a href=\"default.php?$subUrl\"><img src=\"".$modulesDir.$moduleDir."imgs/return.gif\" height=\"31\" width=\"32\" alt=\"Return\" border=\"none\"/></a><span class=\"moduleReturnText\">Return to Gallery Administration</span>"; } else { echo "File upload is not valid. Check permissions or contact the system administrator."; echo "<br /><br />"; echo "<a href=\"default.php?$subUrl\"><img src=\"".$modulesDir.$moduleDir."imgs/return.gif\" height=\"31\" width=\"32\" alt=\"Return\" border=\"none\"/></a><span class=\"moduleReturnText\">Return to Gallery Administration</span>"; } } } else { $query = "UPDATE gallery SET description='$descriptionPost', aid='$albumPost' WHERE iid='$iid'"; $result = mysql_query($query, $connection) or die("Query failed : " . mysql_error()); echo "Thank you, the image has been modified. This image can be further edited at any time from the Gallery section of the administration." ."<br /><br />"; echo "<a href=\"default.php?$subUrl\"><img src=\"".$modulesDir.$moduleDir."imgs/return.gif\" height=\"31\" width=\"32\" alt=\"Return\" border=\"none\"/></a><span class=\"moduleReturnText\">Return to Gallery Administration</span>"; } } ELSE { //code to display the editor which replaces the textarea. echo "<script type=\"text/javascript\" src=\"" ."$docroot" ."editor/fckeditor.js\"></script>" ."<script type=\"text/javascript\">" ."window.onload = function()" ."{" ."var oFCKeditor = new FCKeditor( 'description','','250','Default','' ) ;" ."oFCKeditor.BasePath = '" ."$docroot" ."editor/' ;" ."oFCKeditor.ReplaceTextarea() ;" ."}" ."</script>"; //editor code end $query = "SELECT * FROM gallery WHERE iid=$iid"; $result = mysql_query($query, $connection) or die("Query failed : " . mysql_error()); $imageName = mysql_result($result,0,"imageName"); $description = mysql_result($result,0,"description"); $aid = mysql_result($result,0,"aid"); IF ($error==2){ echo "<font color=\"red\">Please check to ensure that all fields have been filled.</font><br /><br />"; } echo "<form action=\"default.php?$subUrl&do=modImage&page=submit&iid=$iid\" method=\"post\" enctype=\"multipart/form-data\">" ."<table width=\"100%\">" ."<tr><td valign=\"top\"><b>Current Image: </b></td><td><img src=\"$uploadTHdir"."th_"."$imageName.jpg\" border=0></td></tr>" ."<tr><td width=\"150\"><b>Replace Image: </b></td><td><input name=\"theImage\" type=\"file\" /></td></tr>" ."<tr><td><strong>Album:</strong></td><td>"; IF (($albumPost!=null)||($albumPost!="")){ $curAlbumQuery = "SELECT * FROM galleryalbum where aid=$albumPost"; } ELSE{ $curAlbumQuery = "SELECT * FROM galleryalbum where aid=$aid"; } $curAlbumResult = mysql_query($curAlbumQuery, $connection) or die("Query failed : " . mysql_error()); $curAname = mysql_result($curAlbumResult,0,"aname"); $curAid = mysql_result($curAlbumResult,0,"aid"); echo "<select name=\"album\" size=\"1\">"; $imgAlbumQuery = "SELECT * FROM galleryalbum"; $imgAlbumResult = mysql_query($imgAlbumQuery, $connection) or die("Query failed : " . mysql_error()); $numrows = mysql_num_rows($imgAlbumResult); for ($i = 0; $i < $numrows; $i++) { $listaname = mysql_result($imgAlbumResult,$i,"aname"); $listaid = mysql_result($imgAlbumResult,$i,"aid"); $sel = ( $curAid == $listaid ? " selected" : "" ); echo "<option value=\"$listaid\" $sel>"; echo $listaname; echo "</option>"; } echo "</select>"; echo "</td></tr>"; echo "<tr><td colspan=\"2\" height=\"10\"></td></tr>" ."<tr><td colspan=\"2\"><strong>Description:</strong></td></tr>" ."<tr><td colspan=\"2\"><textarea name=\"description\" rows=\"10\" cols=\"75\">"; if (($descriptionPost!=null)||($descriptionPost!="")){ echo stripslashes($descriptionPost); } else { echo $description; } echo "</textarea></td></tr>" ."<tr><td colspan=\"2\"><input name=\"Submit\" value=\"Submit\" type=\"submit\"></td></tr></table>" ."</form>"; echo "<br />"; echo "<a href=\"default.php?$subUrl&do=viewAlbum&aid=$aid#gallery\"><img src=\"".$modulesDir.$moduleDir."imgs/return.gif\" height=\"31\" width=\"32\" alt=\"Return\" border=\"none\"/></a><span class=\"moduleReturnText\">Return to Gallery Administration</span>"; } } ELSEIF ($do == "delImage") { $curpage = $_GET["curpage"]; $action = $_GET["action"]; $iid = $_GET["iid"]; $aid = $_GET["aid"]; echo "<span class=\"actionHead\">Remove an Image</span><br /><br />"; IF ($action=="yes"){ $query = "SELECT imageName FROM gallery WHERE iid=$iid"; $result=mysql_query($query, $connection) or die("Query failed : " . mysql_error()); $imageName = stripslashes(mysql_result($result,0,"imageName")); $query = "DELETE FROM gallery WHERE iid='$iid'"; mysql_query($query, $connection) or die("Query failed : " . mysql_error()); $imagePath = $uploaddir . $imageName . ".jpg"; $imageTHPath = $uploadTHdir . "th_" . $imageName . ".jpg"; chmod($imagePath, 0755); chmod($imageTHPath, 0755); unlink($imagePath); unlink($imageTHPath); echo "The Image has been removed.<br />"; echo "<br />"; echo "<a href=\"default.php?$subUrl&do=viewAlbum&aid=$aid&curpage=$curpage#gallery\"><img src=\"".$modulesDir.$moduleDir."imgs/return.gif\" height=\"31\" width=\"32\" alt=\"Return\" border=\"none\"/></a><span class=\"moduleReturnText\">Return to Gallery Administration</span>"; } ELSE{ echo "Are you sure you wish to remove this image from the gallery?"; echo "<br /><br />"; echo "<a href=\"default.php?$urlString&action=yes&iid=$iid\"><img src=\"".$modulesDir.$moduleDir."imgs/accept.gif\" height=\"32\" width=\"32\" alt=\"Accept\" border=\"none\"/></a> Accept"; echo " "; echo "<a href=\"default.php?$subUrl&do=viewAlbum&aid=$aid&curpage=$curpage#gallery\"><img src=\"".$modulesDir.$moduleDir."imgs/cancel.gif\" height=\"32\" width=\"32\" alt=\"Cancel\" border=\"none\"/></a> Cancel"; } } ELSEIF ($do == "addAlbum") { echo "<span class=\"actionHead\">Add an Album</span><br /><br />"; $page = $_GET["page"]; $anamePost = addslashes($_POST["aname"]); $descriptionPost = addslashes($_POST["description"]); if($page=="submit"){ $error = chkAlbumElements($anamePost,$descriptionPost); $albumError = chkAlbum($anamePost); } IF (($page=="submit")&&($error==5)&&$albumError==0){ $query = "INSERT INTO galleryalbum VALUES('','$anamePost','$descriptionPost')"; $result = mysql_query($query, $connection) or die("Query failed : " . mysql_error()); echo "Thank you, the album <b>$aname</b> has been added. You can now add pictures to this album." ."<br /><br />"; echo "<a href=\"default.php?$subUrl&aid=$aid&curpage=$curpage#gallery\"><img src=\"".$modulesDir.$moduleDir."imgs/return.gif\" height=\"31\" width=\"32\" alt=\"Return\" border=\"none\"/></a><span class=\"moduleReturnText\">Return to Gallery Administration</span>"; } ELSE{ IF ($albumError==1){ echo "<font color=\"red\">This album already exists, please try a different name for the album</font><br />"; } IF ($error==2){ echo "<font color=\"red\">Please check to ensure that all fields have been filled.</font><br /><br />"; } //code to display the editor which replaces the textarea. echo "<script type=\"text/javascript\" src=\"" ."$docroot" ."editor/fckeditor.js\"></script>" ."<script type=\"text/javascript\">" ."window.onload = function()" ."{" ."var oFCKeditor = new FCKeditor( 'description','','150','Internal','' ) ;" ."oFCKeditor.BasePath = '" ."$docroot" ."editor/' ;" ."oFCKeditor.ReplaceTextarea() ;" ."}" ."</script>"; //editor code end echo "<br />" ."<table width=\"100%\">" ."<form enctype=\"multipart/form-data\" action=\"default.php?$urlString&page=submit\" method=\"POST\">" ."<tr><td width=\"120\">" ."<b>Album Name: </b></td><td><input type=\"text\" name=\"aname\" size=\"40\" value="; IF ($albumPost!=null){ echo $albumPost; } echo "></td></tr>" ."<tr><td colspan=\"2\" height=\"10\"></td></tr>" ."<tr><td colspan=\"2\"><b>Description:</b><br /></td></tr>" ."<tr><td colspan=\"2\" height=\"100\"><textarea name=\"description\" rows=\"8\" cols=\"75\">"; IF ($descriptionPost!=null){ echo $descriptionPost; } echo "</textarea></td></tr>" ."<tr><td colspan=\"2\" height=\"10\"></td></tr>" ."<tr><td colspan=\"2\" height=\"10\">" ."<input type=\"submit\" value=\"Submit\" />" ."</td></tr>" ."</form>" ."</table>" ."<br /><br />"; echo "<a href=\"default.php?$subUrl&aid=$aid&curpage=$curpage#gallery\"><img src=\"".$modulesDir.$moduleDir."imgs/return.gif\" height=\"31\" width=\"32\" alt=\"Return\" border=\"none\"/></a><span class=\"moduleReturnText\">Return to Gallery Administration</span>"; } } ELSEIF ($do=="editAlbum"){ $page=$_GET['page']; $aid = $_GET['aid']; $anamePost= addslashes($_POST['aname']); $descriptionPost= addslashes($_POST['description']); if($page=="submit"){ $error = chkAlbumElements($anamePost,$descriptionPost); $albumError = chkAlbum($anamePost); } echo "<span class=\"actionHead\">Modify an Album</span><br /><br />"; IF (($page=="submit")&&($error==5)&&($albumError==0)){ $query = "UPDATE galleryalbum SET aname='$anamePost', description='$descriptionPost' WHERE aid='$aid'"; $result = mysql_query($query, $connection) or die("Query failed : " . mysql_error()); echo "Thank you, the album has been modified. All images associated with the album before modification will still exist with this album." ."<br /><br />"; echo "<a href=\"default.php?$subUrl\"><img src=\"".$modulesDir.$moduleDir."imgs/return.gif\" height=\"31\" width=\"32\" alt=\"Return\" border=\"none\"/></a><span class=\"moduleReturnText\">Return to Gallery Administration</span>"; } ELSE{ IF ($albumError==1){ echo "<font color=\"red\">This album already exists, please try a different name for the album</font><br />"; } IF ($error==2){ echo "<font color=\"red\">Please check to ensure that all fields have been filled.</font><br /><br />"; } //code to display the editor which replaces the textarea. echo "<script type=\"text/javascript\" src=\"" ."$docroot" ."editor/fckeditor.js\"></script>" ."<script type=\"text/javascript\">" ."window.onload = function()" ."{" ."var oFCKeditor = new FCKeditor( 'description','','150','Internal','' ) ;" ."oFCKeditor.BasePath = '" ."$docroot" ."editor/' ;" ."oFCKeditor.ReplaceTextarea() ;" ."}" ."</script>"; //editor code end $query = "SELECT * FROM galleryalbum WHERE aid='$aid'"; $result = mysql_query($query, $connection) or die("Query failed : " . mysql_error()); $aname = stripslashes(mysql_result($result,0,"aname")); $description = stripslashes(mysql_result($result,0,"description")); echo "<form action=\"default.php?$subUrl&do=editAlbum&page=submit&aid=$aid\" method=\"post\" enctype=\"multipart/form-data\">" ."<table width=\"100%\">" ."<tr><td width=\"80\"><strong>Album:</strong></td><td><input type=\"text\" name=\"aname\" size=\"40\" value=\""; if (($anamePost!=null)||($anamePost!="")){ echo stripslashes($anamePost); } else{ echo $aname; } echo "\"></td></tr>" ."<tr><td colspan=\"2\" height=\"10\"></td></tr>" ."<tr><td colspan=\"2\"><strong>Description:</strong></td></tr>" ."<tr><td colspan=\"2\"><textarea name=\"description\" rows=\"10\" cols=\"75\">"; if (($descriptionPost!=null)||($descriptionPost!="")){ echo stripslashes($descriptionPost); } else{ echo $description; } echo "</textarea></td></tr>" ."<tr><td colspan=\"2\"><input name=\"Submit\" value=\"Submit\" type=\"submit\"></td></tr></table>" ."</form>"; echo "<br />"; echo "<a href=\"default.php?$subUrl\"><img src=\"".$modulesDir.$moduleDir."imgs/return.gif\" height=\"31\" width=\"32\" alt=\"Return\" border=\"none\"/></a><span class=\"moduleReturnText\">Return to Gallery Administration</span>"; } } ELSEIF ($do=="delAlbum"){ $action = $_GET["action"]; $aid = $_GET["aid"]; echo "<span class=\"actionHead\">Album Deletion</span><br /><br />"; $error = isAlbumEmpty($aid); IF (($action=="yes")&&($error!=1)){ $query = "DELETE FROM galleryalbum WHERE aid=$aid"; $result = mysql_query($query, $connection) or die("Query failed : " . mysql_error()); echo "The album has been deleted."; echo "<br /><br />"; echo "<a href=\"default.php?$subUrl\"><img src=\"".$modulesDir.$moduleDir."imgs/return.gif\" height=\"31\" width=\"32\" alt=\"Return\" border=\"none\"/></a><span class=\"moduleReturnText\">Return to Gallery Administration</span>"; } ELSE{ IF ($error==1){ echo "<font color=\"red\">This album cannot be removed as it has images associated with it. Return to the Gallery Administration and either transfer the images or remove them from this album before it can be deleted.</font><br /><br />"; echo "<a href=\"default.php?$subUrl\"><img src=\"".$modulesDir.$moduleDir."imgs/return.gif\" height=\"31\" width=\"32\" alt=\"Return\" border=\"none\"/></a><span class=\"moduleReturnText\">Return to Gallery Administration</span>"; } ELSE{ $error= 0; echo "Are you sure you wish to delete this album?"; echo "<br /><br />"; echo "<a href=\"default.php?$urlString&action=yes&aid=$aid\"><img src=\"".$modulesDir.$moduleDir."imgs/accept.gif\" height=\"32\" width=\"32\" alt=\"Accept\" border=\"none\"/></a> Accept"; echo " "; echo "<a href=\"default.php?$subUrl\"><img src=\"".$modulesDir.$moduleDir."imgs/cancel.gif\" height=\"32\" width=\"32\" alt=\"Cancel\" border=\"none\"/></a> Cancel"; } } } ELSEIF ($do=="viewImage"){ $aid = $_GET["aid"]; $iid = $_GET["iid"]; $curpage = $_GET["curpage"]; $query = "SELECT * FROM gallery WHERE iid=$iid"; $result=mysql_query($query, $connection) or die("Query failed : " . mysql_error()); $imageName = stripslashes(mysql_result($result,0,"imageName")); $description = stripslashes(mysql_result($result,0,"description")); $aid = stripslashes(mysql_result($result,0,"aid")); $queryAlbum = "SELECT aname FROM galleryalbum WHERE aid=$aid"; $resultAlbum =mysql_query($queryAlbum, $connection) or die("Query failed : " . mysql_error()); $aname = stripslashes(mysql_result($resultAlbum,0,"aname")); echo "<span class=\"actionHead\">Image Details</span><br /><br />"; echo "<img src=\"$uploaddir$imageName.jpg\" border=\"0\">"; echo "<br /><br />"; echo "<strong>Current Album:</strong> $aname<br />"; echo "<strong>Description:</strong> $description"; echo "<br /><br />"; echo "<a href=\"default.php?$subUrl&do=viewAlbum&aid=$aid&curpage=$curpage#gallery\"><img src=\"".$modulesDir.$moduleDir."imgs/return.gif\" height=\"31\" width=\"32\" alt=\"Return\" border=\"none\"/></a><span class=\"moduleReturnText\">Return to Gallery Administration</span>"; } ELSE { $query = "SELECT * FROM galleryalbum"; $result = mysql_query($query, $connection) or die("Query failed1 : " . mysql_error()); $numrows = mysql_numrows($result); if ($numrows!=0){ echo "<table><tr><td width=\"160\">"; echo "<a href=\"default.php?$subUrl&do=addImage\"><img src=\"".$modulesDir.$moduleDir."imgs/addImage.gif\" height=\"32\" width=\"32\" alt=\"Add New Image\" border=\"none\"/></a> Add an Image<br /><br />"; echo "</td><td>"; echo "<a href=\"default.php?$subUrl&do=addAlbum\"><img src=\"".$modulesDir.$moduleDir."imgs/newAlbum.gif\" alt=\"Create Album\" border=\"none\"/></a> Create a New Album<br /><br />"; echo "</td></tr></table>"; echo "<strong>You can browse the following albums: (click album name to view)</strong><br /><br />"; echo "<a name=\"albums\">"; echo "<table cellspacing=\"0\" class=\"albumTable\"><tr class=\"moduleHead\"><td width=\"200\">Album:</td><td width=\"300\">Description</td><td width=\"80\" align=\"center\">Modify</td><td width=\"80\" align=\"center\">Remove</td></tr>"; for ($i = 0 ; $i < $numrows ; $i++) { IF ($i%2==0){ $rowclass = "moduleRowEven"; } ELSE{ $rowclass = "moduleRowOdd"; } $aName = stripslashes(mysql_result($result,$i,"aName")); $description = stripslashes(mysql_result($result,$i,"description")); $aid = stripslashes(mysql_result($result,$i,"aid")); $nums = $i + 1; echo "<tr class=\"$rowclass\"><td><span class=\"galleryNums\">$nums.</span> <a href=\"default.php?$subUrl&do=viewAlbum&aid=$aid#gallery\" class=\"galleryLinks\">$aName</a></td>"; echo "<td><i>$description</i></td><td align=\"center\"><a href=\"default.php?$subUrl&do=editAlbum&aid=$aid\"><img src=\"".$modulesDir.$moduleDir."imgs/modify.gif\" height=\"32\" width=\"32\" alt=\"Modify\" border=\"none\" title=\"Modify Image\"/></a></td><td align=\"center\"><a href=\"default.php?$subUrl&do=delAlbum&aid=$aid\"><img src=\"".$modulesDir.$moduleDir."imgs/delete.gif\" height=\"32\" width=\"32\" alt=\"Delete\" border=\"none\" title=\"Delete Image\"/></a></td></tr>"; } IF ($rowclass=="moduleRowEven"){ $rowclass="moduleRowOdd"; } ELSE { $rowclass="moduleRowEven"; } $nums = $nums+1; echo "<tr class=\"$rowclass\"><td><span class=\"galleryNums\">$nums.</span> <a href=\"default.php?$subUrl&do=viewAlbum&aid=viewall#gallery\" class=\"galleryLinks\">View All Images</a></td><td><i>View all images from all albums.</i></td><td align=\"center\"> - </td><td align=\"center\"> - </td></tr></table><br /><br />"; IF ($do=="viewAlbum"){ $aid = $_GET["aid"]; $pageNum = 1; if(isset($_REQUEST['curpage'])) { $pageNum = $_REQUEST['curpage']; } // Get the offset value $offset = ($pageNum - 1) * $picsPerPage; // Get the number of pages IF ($aid=="viewall"){ $query = "SELECT iid FROM gallery"; } ELSE { $query = "SELECT iid FROM gallery where aid=$aid"; } $result = mysql_query($query) or die("Query failed2 : " . mysql_error()); $numrows = mysql_numrows($result); IF ($numrows!=0){ $maxPage = ceil($numrows/$picsPerPage); // The following logic will find out if we should display the next/first and prev/last links if ($pageNum > 1) { $curpage = $pageNum - 1; $prev = " <a href=\"default.php?$subUrl&aid=$aid&do=viewAlbum&curpage=$curpage#gallery\">[Prev]</a> "; $first = " <a href=\"default.php?$subUrl&aid=$aid&do=viewAlbum&curpage=1#gallery\">[First Page]</a> "; } else { $prev = " [Prev] "; $first = " [First Page] "; } if ($pageNum < $maxPage) { $curpage = $pageNum + 1; $next = " <a href=\"default.php?$subUrl&aid=$aid&do=viewAlbum&curpage=$curpage#gallery\">[Next]</a> "; $last = " <a href=\"default.php?$subUrl&aid=$aid&do=viewAlbum&curpage=$maxPage#gallery\">[Last Page]</a> "; } else { $next = " [Next] "; $last = " [Last Page] "; } echo "<a name=\"gallery\">"; // print start of table and header row echo "<table class=\"albumTable\" width=700 cellpadding=\"0\" cellspacing=\"0\">"; // -- PORTABLE PAGING CODE ABOVE -- // IF ($aid=="viewall"){ $query = "SELECT * FROM gallery ORDER BY iid DESC LIMIT $offset, $picsPerPage"; $aname = "All Pictures"; } ELSE{ $query = "SELECT * FROM gallery WHERE aid=$aid ORDER BY iid DESC LIMIT $offset, $picsPerPage"; $queryAlbumName = "SELECT * FROM galleryalbum WHERE aid=$aid"; $resultAlbumName=mysql_query($queryAlbumName, $connection) or die("Query failed3 : " . mysql_error()); $aname = mysql_result($resultAlbumName,0,"aname"); } $result=mysql_query($query, $connection) or die("Query failed4 : " . mysql_error()); //$numrows = mysql_numrows($result); // PRINT THE GALLERY echo "<tr><td class=\"moduleHead\" colspan=$itemsPerRow align=center>Album: <i>$aname</i> | Viewing $numrows Pictures</td></tr>"; // print the page navigation link echo "<tr><td colspan=$itemsPerRow height=\"40\" align=\"center\">"; echo "<form method=\"POST\" action=\"default.php?$subUrl&aid=$aid&do=viewAlbum\">"; echo "$first $prev Viewing page <b>$pageNum</b> of <b>$maxPage</b> $next $last"; echo " "; echo "<select name=\"curpage\">"; echo "<option value=\"1\" selected>Jump to..."; for ($i = 0; $i < $maxPage; $i++) { $j=$i+1; echo "<option value=\"$j\">Page $j"; } echo "</select>"; echo "<input type=\"submit\" value=\"Go\">"; echo "</form>"; echo "</td></tr>"; $numrows = mysql_num_rows($result); for ($i = 0 ; $i < $picsPerPage && $i < $numrows; $i++) { IF (($itemCount%$itemsPerRow)==0){ echo "<tr height=$trHeight>"; } $imageName = mysql_result($result,$i,"imageName") . ".jpg"; $iid = mysql_result($result,$i,"iid"); echo "<td width=$tdWidth>"; echo "<table><tr><td>"; echo "<img src=\"" . $uploadTHdir . "th_" . $imageName . "\" border=0>"; echo "</td><td align=\"center\">"; echo "<a href=default.php?$subUrl&curpage=$pageNum&do=viewImage&iid=$iid&aid=$aid><img src=\"".$modulesDir.$moduleDir."imgs/enlargeImg.gif\" height=\"32\" width=\"32\" alt=\"Enlarge Image\" border=\"none\" title=\"View Large Image\"/></a>"; echo "<br /><br />"; echo "<a href=default.php?$subUrl&curpage=$pageNum&do=modImage&iid=$iid&aid=$aid><img src=\"".$modulesDir.$moduleDir."imgs/modify.gif\" height=\"32\" width=\"32\" alt=\"Modify\" border=\"none\" title=\"Modify Image\"/></a>"; echo "<br /><br />"; echo " <a href=default.php?$subUrl&curpage=$pageNum&do=delImage&iid=$iid&aid=$aid><img src=\"".$modulesDir.$moduleDir."imgs/delete.gif\" height=\"32\" width=\"32\" alt=\"Delete\" border=\"none\" title=\"Delete Image\"/></a>"; echo "</td></tr></table>"; echo "</td>"; IF(($itemCount%$itemsPerRow)==($itemsPerRow-1)){ echo "</tr>"; } $itemCount++; } echo "</table>"; echo "<br /><br /><a href=\"default.php?module=Gallery\"><img src=\"".$modulesDir.$moduleDir."imgs/return.gif\" height=\"31\" width=\"32\" alt=\"Return\" border=\"none\"/></a> Return to Album Listing"; } Else{ IF ($aid==viewall){ echo "<strong>There have been no images added to the system.</strong>"; } Else{ $queryAlbumName = "SELECT * FROM galleryalbum WHERE aid=$aid"; $resultAlbumName=mysql_query($queryAlbumName, $connection) or die("Query failed5 : " . mysql_error()); $aname = mysql_result($resultAlbumName,0,"aname"); echo "<table class=\"albumTable\" width=\"600\" cellpadding=\"0\" cellspacing=\"0\">"; echo "<tr><td class=\"moduleHead\" colspan=$itemsPerRow align=center>Album: <i>$aname</i> | Currently Empty</td></tr>"; echo "</table>"; } } } //end viewAlbum } else{ echo "<a href=\"default.php?$subUrl&do=addAlbum\"><img src=\"".$modulesDir.$moduleDir."imgs/newAlbum.gif\" alt=\"Create Album\" border=\"none\"/></a> Create a New Album<br /><br />"; echo "It has been detected that there have been no albums added to the system. Create an album before adding images. Albums aide in organizing images into specific groups for ease of editing."; } } }/*End session login*/ //IF attempt is made through URL but no access is granted. else if((($_SESSION['loggedin'])==yes)&&($access=='0')) { echo "<br />"; echo "The current user does not have access to this module. Please contact the system admin if access is required."; echo "<br /><br />"; } /*If session is not started, display the log in page*/ else { header("Location: default.php"); } function getFileExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } function chkAlbum($album){ GLOBAL $connection; GLOBAL $aid; $oldName = strtolower(mysql_result(mysql_query("SELECT * FROM galleryalbum WHERE aid=$aid"),0,"aname")); $flag=0; $query = "SELECT aname FROM galleryalbum"; $result = mysql_query($query, $connection) or die("Query failedA : " . mysql_error()); $numrows = mysql_num_rows($result); for ($i = 0; $i < $numrows; $i++) { $aname = mysql_result($result,$i,"aname"); IF (strtolower($aname) == strtolower($album) && strtolower($aname) != $oldName){ $flag = 1; } } return $flag; } function isAlbumEmpty($aid){ GLOBAL $connection; $flag=0; $query = "SELECT * FROM gallery WHERE aid=$aid"; $result = mysql_query($query, $connection) or die("Query failedB : " . mysql_error()); $numrows = mysql_num_rows($result); IF ($numrows==0){ $flag = 0; } ELSE{ $flag = 1; } return $flag; } function chkGalleryElements($image,$album,$description){ IF((customTrim($image)==1)||(customTrim($album)==1)||(customTrim($description)==1)){ $error=2; } ELSE{ $error=5; } return $error; } function chkModGalleryElements($album,$description){ IF((customTrim($album)==1)||(customTrim($description)==1)){ $error=2; } ELSE{ $error=5; } return $error; } function chkAlbumElements($aname,$description){ IF((customTrim($aname)==1)||(customTrim($description)==1)){ $error=2; } ELSE{ $error=5; } return $error; } function chkUser($user){ GLOBAL $connection; $flag=0; $query = "SELECT username FROM users"; $result = mysql_query($query, $connection) or die("Query failed : " . mysql_error()); $numrows = mysql_num_rows($result); for ($i = 0; $i < $numrows; $i++) { $username = mysql_result($result,$i,"username"); IF (strtolower($username) == strtolower($user)){ $flag = 1; } } return $flag; } function customTrim($string){ if(trim($string)==""){ $error=1; } return $error; }
  16. I am having a very difficult time trying to get my query to work correctly and at the moment it does not do what I need it to do. Here is what I want to do SELECT account_num from patient_info where dob='1901' OR dob ='1912' OR dob ='1940' Than loop throu the result set and run another query like so foreach ($accounts as $account) { $q=$this->db->query("SELECT account_num FROM ( SELECT account_num, CONCAT(prescription,'-',dosage) as script FROM ci_prescription_history )a WHERE script='".implode("' OR script ='",$doses)."' AND account_num=$account"); } Then run another query similar to the one above. But this does not work for me because it will grab any row which matches either of the OR statements when I need it to match both. So I tried running this query but it returns an empty set. $foreach ($accounts as $account) { q=$this->db->query("SELECT account_num FROM ( SELECT account_num, CONCAT(prescription,'-',dosage) as script FROM ci_prescription_history )a WHERE script='".implode("' AND script ='",$doses)."' AND account_num=$account"); } I also tried using the IN clause but thats the same as the OR statement. How can I accomplish this query? I am still learning advance queries so please bare with me.
  17. I have a script that takes the user's input and stores it in a database. Part of the script geo codes the address into lat and lng. What I would like to do is to store those results into the database. I can't seem to store the lat and lng. This is part of the code from the point where it geo codes to the end of the script: $address = $_POST["cross_streets"]; $prepAddr = str_replace(' ','+',$address); $geocode=file_get_contents('http://maps.google.com/maps/api/geocode/json?address='.$prepAddr.'&sensor=false'); $output= json_decode($geocode); $lat = $output->results[0]->geometry->location->lat; $lng = $output->results[0]->geometry->location->lng; /* -------------------------------------------------------------------------------------------------- SAVE TO DATABASE ------------------------------------------------------------------------------------ -------------------------------------------------------------------------------------------------- */ if(!$_POST["title"] || !$_POST["rent"] || !$_POST["fees"]){ header('location: fields.php'); } else if(!(preg_match('#^\d+(\.(\d{2}))?$#',($_POST["rent"])))){ header('location: rent.php'); } //validate captcha else if(($_SESSION['security_code'] != $_POST['security_code']) || (empty($_SESSION['security_code'])) ){ header( 'Location: captcha.php' ) ; }else{ $con = mysql_connect("localhost","",""); if (!$con){die('Could not connect: ' . mysql_error());} } mysql_select_db("", $con); $sql = "INSERT INTO apartments (username, title, county, town, type, description, cross_streets, phone, contact, office, pets, email, rooms, bath, square, rent, fees, service, space, feeornofee, lease, youtube, videotitle, lat='$lat', lng='$lng', imageurl1, imageurl2, imageurl3, imageurl4, imageurl5, imageurl6, imageurl7, imageurl8, imageurl9, imageurl10, imageurl11, imageurl12, date_created) VALUES ('".$myusername."', '".mysql_real_escape_string($_POST['title'])."', '".mysql_real_escape_string($_POST['county'])."', '".mysql_real_escape_string($_POST['town'])."', '".mysql_real_escape_string($_POST['type'])."', '".mysql_real_escape_string($_POST['description'])."', '".mysql_real_escape_string($_POST['cross_streets'])."', '".mysql_real_escape_string($_POST['phone'])."', '".mysql_real_escape_string($_POST['contact'])."', '".mysql_real_escape_string($_POST['office'])."', '".mysql_real_escape_string($_POST['pets'])."', '".mysql_real_escape_string($_POST['email'])."', '".$_POST[('rooms')]."', '".mysql_real_escape_string($_POST['bath'])."', '".mysql_real_escape_string($_POST['square'])."', '".mysql_real_escape_string($_POST['rent'])."', '".mysql_real_escape_string($_POST['fees'])."', '".mysql_real_escape_string($_POST['service'])."', '".mysql_real_escape_string($_POST['space'])."', '".mysql_real_escape_string($_POST['feeornofee'])."', '".mysql_real_escape_string($_POST['lease'])."', '".mysql_real_escape_string($_POST[('youtube')])."', '".mysql_real_escape_string($_POST[('videotitle')])."', '".mysql_real_escape_string($_POST['lat'])."', '".mysql_real_escape_string($_POST['lng'])."','".mysql_real_escape_string($images[1])."', '".mysql_real_escape_string($images[2])."', '".mysql_real_escape_string($images[3])."', '".mysql_real_escape_string($images[4])."', '".mysql_real_escape_string($images[5])."', '".mysql_real_escape_string($images[6])."', '".mysql_real_escape_string($images[7])."', '".mysql_real_escape_string($images[8])."', '".mysql_real_escape_string($images[9])."', '".mysql_real_escape_string($images[10])."', '".mysql_real_escape_string($images[11])."', '".mysql_real_escape_string($images[12])."', NOW())"; $result = mysql_query($sql) or die(mysql_error()); header('Location: success.php') ; }//end if
  18. hello guys im kind of new to this so please be nice. i am looking for advice more on the hprocess of how to do something rather than the exact code. maybe somebody could give me a short guide or step to step process idea. my task is to have an events page on a website i am making for an assignment. the events page must display the 5 nearest upcoming events the user must also be able to rearrange the events by distance or type of even. the events will be stored in a database. could somebody please offer me some advice on the best process to follow to do this task. thanks a bunch
  19. hello guys i have made a basic database in myadmin and i have written php code to connect to it. my database is called products. When i run the page i get the output - Connection Successful could not connect to products can somebody look at my code and tell me why i can not connect to my database <?php $host="localhost"; $user=""; $password=""; $db = "products"; $connect = mysql_connect($host, $user, $password); if($connect) { echo "Connection Successful"; $select = mysql_select_db($db); if ($select) { echo "<br /> connected to ".$db; } else { echo "<be /> could not connect to ".$db; } } else { echo "failed connection"; } ?> thankyou
  20. HI, Im trying to insert into a table then return the last id then INSERT to another table using this id... here is the code, hopefully it makes more sense mysql_query("INSERT INTO `books` ($fields1) VALUES ($data1)"); // query to insert the book //data //into the database $lastId = mysql_insert_id(); mysql_query("INSERT INTO `userBooks` `user_id`,`book_id` VALUES '$sessionUserId', '$lastId'"); Just to note the first query works perfectly, also user_id and book_id in the userBooks tables are foreign keys but that shouldnt make a difference. Please someone help. Thanks in advance Dbewick123
  21. Okay so i am having issues with a mySQL nested select statement. I will post code below but what i am trying to achieve is to compare a value from table 1 (books) and table2 (userbooks) and return the row from books 2 if the comparison is correct. Here is my code for the query $fields = '`' . implode('`, `', $funcGetArgs) . '`'; // this will be fields from database, so values stored under book name etc. $bookData = mysql_fetch_assoc(mysql_query(“SELECT $fields FROM `books` WHERE `tag1` = (SELECT `tag1` FROM `userBooks` WHERE `user_id` = $user_id”))); As you can see I define the $fields via $funcGetArgs so that the passed in parameters are the fields that are retrieved. To recap I want to be able to SELECT a value from `books` compare it with a value from `userBooks` and return the row data if the two values are the same (if true is returned from the comparison). If anyone can think or a way I could do this, even if its not with the ‘mysql_fetch_assoc’ method please help. Thanks
  22. i have 2 tables, items and users. item has => item_id(unique_1), item_describe,item_cost,item_unit_price user => user_name, psws, last_name so whenever user logins inside and adds a item, i want to connect that adding of items with the user. may b looks simple, but i want to do it without adding any extra field in tables.. is that possible.. Or else if i make item_id as primary, then how should i proceed? And if item_id is not unique, if 2 users have same items addition with same id,cost_price, how could that be achieved?? thnks in advance...
  23. Hi i am having a problem getting the order by DESC in my table working correctly <p>All walks are listed in order with the latest at the top. Walks can be filtered by area using the drop-down box. The abbreviated Area ID's are as follows:<br/> YD - Yorkshire Dales<br/> LD - Lake District<br/> FB - Forest of Bowland<br/> WPM - West Pennine Moors<br/> PD - Peak District<br/> LOC - Local<br/> O - Other<br/></p> </div> <!-- Selects walk area --> <br /> <form id="form1" name="form1" method="post" action="walk_results.php"> <label>Area</label> <select name="area_id"> <option value="">All</option> <?php $sql_result = mysql_query("SELECT * FROM walk GROUP BY area_id ORDER BY walk_date DESC"); while ($row = mysql_fetch_assoc($sql_result)) { echo "<option value='".$row["area_id"]."'".($row["area_id"]==$_REQUEST["area_id"]? " selected" : "").">".$row["area_id"]."</option>"; }; ?> <!-- Submits walk area --> </select> </label> <input type="submit" name="button" id="button" class="styled-button" value="Select Area" /></form> <style type="text/css"> .styled-button { -webkit-box-shadow:rgba(0,0,0,0.2) 0 1px 0 0; -moz-box-shadow:rgba(0,0,0,0.2) 0 1px 0 0; box-shadow:rgba(0,0,0,0.2) 0 1px 0 0; border-bottom-color:#333; border:1px solid #6470ED; background-color:#6470ED; border-radius:3px; -moz-border-radius:5px; -webkit-border-radius:5px; color:#fff; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; text-shadow:#b2e2f5 0 1px 0; padding:2px } </style> </select> </label> <!-- Walk area results table --> <div id= "result"> <br /><br /> <table width="900" border="1" cellspacing="1" cellpadding="4"> <tr> <td width="84" bgcolor="#6470ED" align="center"><strong>Select Walk</strong></td> <td width="75" bgcolor="#6470ED" align="center"><strong>Walk Date</strong></td> <td width="360" bgcolor="#6470ED" align="center"><strong>Title</strong></td> <td width="64" bgcolor="#6470ED" align="center"><strong>Distance (Miles)</strong></td> <td width="85" bgcolor="#6470ED" align="center"><strong>Ascent</strong></td> <td width="78" bgcolor="#6470ED" align="center"><strong>Time</strong></td> <td width="67" bgcolor="#6470ED" align="center"><strong>Area Id</strong></td> </tr> <?php if ($_REQUEST["area_id"]<>'') { $search_area_id = "AND area_id='".mysql_real_escape_string($_REQUEST["area_id"])."'"; } if ($_REQUEST["from"]<>'' and $_REQUEST["to"]<>''){ } else { $sql = "SELECT * FROM walk WHERE walk_id>\"\"".$search_string.$search_area_id ; } $sql_result= mysql_query ($sql) or die ('request"Error"'.$sql); #echo "SQL $sql"; --- to view info --- $clicked =$_REQUEST["area_id"]; $sql= "SELECT * FROM walk WHERE area_id = '$clicked' ORDER BY walk_id"; if (mysql_num_rows($sql_result)>0) { while ($row = mysql_fetch_assoc($sql_result)) { $id = $row['walk_id']; $date_of_walk = $row['walk_date']; $date_of_walk = date("d.m.Y", strtotime($date_of_walk)); #echo "id $id<br>"; --- to view info --- ?> <!-- Table Results --> <tr> <td><?php echo "<a href='walk_info.php?walk_id=$id'>Select Walk"?></a></td> <td><?php echo $row['walk_date']=$date_of_walk; ?></td> <td><?php echo $row["title"]; ?></td> <td><?php echo $row["distance"]; ?></td> <td><?php echo $row["ascent"]; ?></td> <td><?php echo $row["time"]; ?></td> <td><?php echo $row["area_id"]; ?></td> </tr> <?php } } else { $row= mysql_fetch_assoc($sql_result);$sql_result= mysql_query ($sql); ?> <tr><td colspan="5">No results found.</td> <?php } mysql_close()?>
  24. Hey guys, thanks for reading my post. I'm banging my head against a brick wall with this one, I have very limited knowledge of Mysql statements unfortunately. I'm trying to select data from a table that contains product purchases and find out which customers have purchased two seperate products, the code I have for this so far is: $brand = $_GET["brand"]; $brand2 = $_GET["brand2"]; $result = mysql_query('SELECT * FROM sample WHERE `nice_date` >= "'.$year.'-01-01" and `nice_date` < "'.$year.'-01-31" AND `product_name` LIKE "%'.$brand.'%" AND `product_name` LIKE "%'.$brand2.'%" '); However, this simply finds products that contain $brand and $brand2, whereas I'm trying to look for results where both brands were purchased. Once again, thanks for reading and any pointers would be brilliant.
  25. I have one code which I use to add articles in shopping cart. In another website working without any kind of problem, but on new one he makes me problem, he add me double article in shopping cart. I press once “add to basket” but he put me twice that articles. When I press “add to basket” I calling this code to found out which articles is: <?php session_start(); $var=$_SERVER['REQUEST_URI']; //reading $id = substr(strrchr($var, "korpa?"),6 );//reading first element after "?" $tbl_name="description"; //table name $_SESSION['korpa']+=$row[price]; if($_SESSION['numproduct']==0){ $_SESSION['articles']=array($id); $_SESSION[numproduct]++; }else{ array_push($_SESSION['articles'],$id); $_SESSION[numproduct]++; } redirect("javascript: history.go(-1)"); ?> On main page I using this code to see what exist in shopping cart: $i=0; $tbl_name="description"; $query = count($_SESSION['articles']); if($query==0){ echo "Your shopping cart is empty."; }else{ echo "In your shopping cart exist:<br/><br/>"; for($i=0;$i<=$query-1;$i++){ $br=$i+1; connect(); $element=$_SESSION['articles'][$i]; $sql="SELECT * FROM $tbl_name WHERE id=$element"; $subject_set=mysql_query($sql); $subject=mysql_fetch_array($subject_set); echo " ".$br.". "; echo $subject['name']; echo " - <b>".$subject['prices']." USD</b><br/> "; } echo "<p align=right><a href=index.php?=order class=basket>Order</a> · <a href=includes/delete.php>Delete items</a></p>"; Does anyone knows why articles goes twice in shopping cart?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.